Refactoring Simbrief fares and aircraft (#1054)
* Refactoring simbrief fares and aircraft * Hide user full name/email * Sort PIREP fields desc; fix cargo counts * Change the sorting * Extra logs * Fix tests * Return fare information through the API * Style fixes * Test fix * Another test fix * More fixes * Set aircraft and fares in prefile * Formatting
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Contracts\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a hub to the subfleet is
|
||||||
|
*/
|
||||||
|
class AddAircraftToSimbrief extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('simbrief', function (Blueprint $table) {
|
||||||
|
$table->unsignedInteger('aircraft_id')
|
||||||
|
->nullable()
|
||||||
|
->after('pirep_id');
|
||||||
|
|
||||||
|
// Temp column to hold the calculated fare data for the API
|
||||||
|
// Remove this once the prefile to acars feature is completed
|
||||||
|
$table->mediumText('fare_data')->nullable()->after('ofp_xml');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -119,8 +119,8 @@ aircraft:
|
|||||||
-
|
-
|
||||||
id: 1
|
id: 1
|
||||||
subfleet_id: 1
|
subfleet_id: 1
|
||||||
icao: null
|
icao: B744
|
||||||
iata: null
|
iata: 744
|
||||||
airport_id: KJFK
|
airport_id: KJFK
|
||||||
landing_time: '2020-10-23 07:50:16'
|
landing_time: '2020-10-23 07:50:16'
|
||||||
name: 'Boeing 747-438'
|
name: 'Boeing 747-438'
|
||||||
@@ -136,8 +136,8 @@ aircraft:
|
|||||||
-
|
-
|
||||||
id: 2
|
id: 2
|
||||||
subfleet_id: 2
|
subfleet_id: 2
|
||||||
icao: null
|
icao: B777
|
||||||
iata: null
|
iata: 777
|
||||||
airport_id: LGRP
|
airport_id: LGRP
|
||||||
landing_time: null
|
landing_time: null
|
||||||
name: 'Boeing 777-200'
|
name: 'Boeing 777-200'
|
||||||
@@ -153,8 +153,8 @@ aircraft:
|
|||||||
-
|
-
|
||||||
id: 3
|
id: 3
|
||||||
subfleet_id: 1
|
subfleet_id: 1
|
||||||
icao: null
|
icao: B744
|
||||||
iata: null
|
iata: 744
|
||||||
airport_id: KAUS
|
airport_id: KAUS
|
||||||
landing_time: '2020-10-24 08:50:13'
|
landing_time: '2020-10-24 08:50:13'
|
||||||
name: 'Boeing 747-412'
|
name: 'Boeing 747-412'
|
||||||
@@ -170,8 +170,8 @@ aircraft:
|
|||||||
-
|
-
|
||||||
id: 4
|
id: 4
|
||||||
subfleet_id: 1
|
subfleet_id: 1
|
||||||
icao: null
|
icao: B744
|
||||||
iata: null
|
iata: 744
|
||||||
airport_id: KAUS
|
airport_id: KAUS
|
||||||
landing_time: null
|
landing_time: null
|
||||||
name: 'Boeing 747-436 RETIRED'
|
name: 'Boeing 747-436 RETIRED'
|
||||||
@@ -187,7 +187,7 @@ aircraft:
|
|||||||
-
|
-
|
||||||
id: 5
|
id: 5
|
||||||
subfleet_id: 4
|
subfleet_id: 4
|
||||||
icao: A320
|
icao: 'A320'
|
||||||
iata: '320'
|
iata: '320'
|
||||||
airport_id: EGLL
|
airport_id: EGLL
|
||||||
landing_time: null
|
landing_time: null
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use App\Http\Requests\UpdatePirepRequest;
|
|||||||
use App\Models\Enums\PirepSource;
|
use App\Models\Enums\PirepSource;
|
||||||
use App\Models\Enums\PirepState;
|
use App\Models\Enums\PirepState;
|
||||||
use App\Models\Enums\PirepStatus;
|
use App\Models\Enums\PirepStatus;
|
||||||
|
use App\Models\Fare;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
use App\Models\SimBrief;
|
use App\Models\SimBrief;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@@ -253,23 +254,48 @@ class PirepController extends Controller
|
|||||||
/**
|
/**
|
||||||
* They have a SimBrief ID, load that up and figure out the flight that it's from
|
* They have a SimBrief ID, load that up and figure out the flight that it's from
|
||||||
*/
|
*/
|
||||||
|
$fare_values = [];
|
||||||
|
$simbrief = null;
|
||||||
$simbrief_id = null;
|
$simbrief_id = null;
|
||||||
|
$aircraft = null;
|
||||||
if ($request->has('sb_id')) {
|
if ($request->has('sb_id')) {
|
||||||
$simbrief_id = $request->input('sb_id');
|
$simbrief_id = $request->input('sb_id');
|
||||||
$brief = SimBrief::find($simbrief_id);
|
$simbrief = SimBrief::find($simbrief_id);
|
||||||
$pirep = Pirep::fromSimBrief($brief);
|
$pirep = Pirep::fromSimBrief($simbrief);
|
||||||
|
|
||||||
|
$aircraft = $simbrief->aircraft;
|
||||||
|
$aircraft_list[$aircraft->subfleet->name] = [];
|
||||||
|
$aircraft_list[$aircraft->subfleet->name][$aircraft->id] = $aircraft->name.' - '.$aircraft->registration;
|
||||||
|
|
||||||
|
// Convert the fare data into the expected output format
|
||||||
|
if (!empty($simbrief->fare_data)) {
|
||||||
|
$fare_values = json_decode($simbrief->fare_data, true);
|
||||||
|
$fares = [];
|
||||||
|
$fare_data = json_decode($simbrief->fare_data, true);
|
||||||
|
foreach ($fare_data as $fare) {
|
||||||
|
$fares[] = new Fare($fare);
|
||||||
|
}
|
||||||
|
|
||||||
|
$aircraft->subfleet->fares = collect($fares);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Set more fields from the Simbrief to the PIREP form
|
||||||
|
} else {
|
||||||
|
$aircraft_list = $this->aircraftList(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('pireps.create', [
|
return view('pireps.create', [
|
||||||
'aircraft' => null,
|
'aircraft' => $aircraft,
|
||||||
'pirep' => $pirep,
|
'pirep' => $pirep,
|
||||||
'read_only' => false,
|
'read_only' => false,
|
||||||
'airline_list' => $this->airlineRepo->selectBoxList(true),
|
'airline_list' => $this->airlineRepo->selectBoxList(true),
|
||||||
'aircraft_list' => $this->aircraftList(true),
|
'aircraft_list' => $aircraft_list,
|
||||||
'airport_list' => $this->airportRepo->selectBoxList(true),
|
'airport_list' => $this->airportRepo->selectBoxList(true),
|
||||||
'pirep_fields' => $this->pirepFieldRepo->all(),
|
'pirep_fields' => $this->pirepFieldRepo->all(),
|
||||||
'field_values' => [],
|
'field_values' => [],
|
||||||
|
'fare_values' => $fare_values,
|
||||||
'simbrief_id' => $simbrief_id,
|
'simbrief_id' => $simbrief_id,
|
||||||
|
'simbrief' => $simbrief,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,12 @@ namespace App\Http\Controllers\Frontend;
|
|||||||
|
|
||||||
use App\Exceptions\AssetNotFound;
|
use App\Exceptions\AssetNotFound;
|
||||||
use App\Models\Aircraft;
|
use App\Models\Aircraft;
|
||||||
|
use App\Models\Enums\FareType;
|
||||||
use App\Models\Enums\FlightType;
|
use App\Models\Enums\FlightType;
|
||||||
|
use App\Models\Fare;
|
||||||
|
use App\Models\Flight;
|
||||||
use App\Models\SimBrief;
|
use App\Models\SimBrief;
|
||||||
|
use App\Models\User;
|
||||||
use App\Repositories\FlightRepository;
|
use App\Repositories\FlightRepository;
|
||||||
use App\Services\FareService;
|
use App\Services\FareService;
|
||||||
use App\Services\SimBriefService;
|
use App\Services\SimBriefService;
|
||||||
@@ -49,8 +53,9 @@ class SimBriefController
|
|||||||
|
|
||||||
$flight_id = $request->input('flight_id');
|
$flight_id = $request->input('flight_id');
|
||||||
$aircraft_id = $request->input('aircraft_id');
|
$aircraft_id = $request->input('aircraft_id');
|
||||||
$flight = $this->flightRepo->with(['subfleets'])->find($flight_id);
|
|
||||||
// $flight = $this->fareSvc->getReconciledFaresForFlight($flight);
|
/** @var Flight $flight */
|
||||||
|
$flight = $this->flightRepo->with(['fares', 'subfleets'])->find($flight_id);
|
||||||
|
|
||||||
if (!$flight) {
|
if (!$flight) {
|
||||||
flash()->error('Unknown flight');
|
flash()->error('Unknown flight');
|
||||||
@@ -63,15 +68,15 @@ class SimBriefController
|
|||||||
return redirect(route('frontend.flights.index'));
|
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
|
// No aircraft selected, show selection form
|
||||||
if (!$aircraft_id) {
|
if (!$aircraft_id) {
|
||||||
|
// If no subfleets defined for flight get them from user
|
||||||
|
if ($flight->subfleets->count() > 0) {
|
||||||
|
$subfleets = $flight->subfleets;
|
||||||
|
} else {
|
||||||
|
$subfleets = $this->userSvc->getAllowableSubfleets($user);
|
||||||
|
}
|
||||||
|
|
||||||
return view('flights.simbrief_aircraft', [
|
return view('flights.simbrief_aircraft', [
|
||||||
'flight' => $flight,
|
'flight' => $flight,
|
||||||
'subfleets' => $subfleets,
|
'subfleets' => $subfleets,
|
||||||
@@ -90,8 +95,14 @@ class SimBriefController
|
|||||||
|
|
||||||
// SimBrief profile does not exists and everything else is ok
|
// SimBrief profile does not exists and everything else is ok
|
||||||
// Select aircraft which will be used for calculations and details
|
// Select aircraft which will be used for calculations and details
|
||||||
|
/** @var Aircraft $aircraft */
|
||||||
$aircraft = Aircraft::where('id', $aircraft_id)->first();
|
$aircraft = Aircraft::where('id', $aircraft_id)->first();
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
// Get passenger and baggage weights with failsafe defaults
|
// Get passenger and baggage weights with failsafe defaults
|
||||||
if ($flight->flight_type === FlightType::CHARTER_PAX_ONLY) {
|
if ($flight->flight_type === FlightType::CHARTER_PAX_ONLY) {
|
||||||
$pax_weight = setting('simbrief.charter_pax_weight', 168);
|
$pax_weight = setting('simbrief.charter_pax_weight', 168);
|
||||||
@@ -115,14 +126,86 @@ class SimBriefController
|
|||||||
$loadmax = 100;
|
$loadmax = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
|
||||||
// Show the main simbrief form
|
// Show the main simbrief form
|
||||||
return view('flights.simbrief_form', [
|
return view('flights.simbrief_form', [
|
||||||
'flight' => $flight,
|
'user' => Auth::user(),
|
||||||
'aircraft' => $aircraft,
|
'flight' => $flight,
|
||||||
'pax_weight' => $pax_weight,
|
'aircraft' => $aircraft,
|
||||||
'bag_weight' => $bag_weight,
|
'pax_weight' => $pax_weight,
|
||||||
'loadmin' => $loadmin,
|
'bag_weight' => $bag_weight,
|
||||||
'loadmax' => $loadmax,
|
'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),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,6 +310,7 @@ class SimBriefController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the OFP was generated. Pass in two items, the flight_id and ofp_id
|
* Check whether the OFP was generated. Pass in two items, the flight_id and ofp_id
|
||||||
|
* This does the actual "attachment" of the Simbrief to the flight
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
*
|
*
|
||||||
@@ -234,10 +318,14 @@ class SimBriefController
|
|||||||
*/
|
*/
|
||||||
public function check_ofp(Request $request)
|
public function check_ofp(Request $request)
|
||||||
{
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = Auth::user();
|
||||||
$ofp_id = $request->input('ofp_id');
|
$ofp_id = $request->input('ofp_id');
|
||||||
$flight_id = $request->input('flight_id');
|
$flight_id = $request->input('flight_id');
|
||||||
|
$aircraft_id = $request->input('aircraft_id');
|
||||||
|
$fares = $request->session()->get('simbrief_fares', []);
|
||||||
|
|
||||||
$simbrief = $this->simBriefSvc->downloadOfp(Auth::user()->id, $ofp_id, $flight_id);
|
$simbrief = $this->simBriefSvc->downloadOfp($user->id, $ofp_id, $flight_id, $aircraft_id, $fares);
|
||||||
if ($simbrief === null) {
|
if ($simbrief === null) {
|
||||||
$error = new AssetNotFound(new Exception('Simbrief OFP not found'));
|
$error = new AssetNotFound(new Exception('Simbrief OFP not found'));
|
||||||
return $error->getResponse();
|
return $error->getResponse();
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class Fare extends Resource
|
|||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'capacity' => $this->capacity,
|
'capacity' => $this->capacity,
|
||||||
'cost' => $this->cost,
|
'cost' => $this->cost,
|
||||||
|
'count' => $this->count ?? 0,
|
||||||
'price' => $this->price,
|
'price' => $this->price,
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
'notes' => $this->notes,
|
'notes' => $this->notes,
|
||||||
|
|||||||
@@ -11,9 +11,27 @@ class SimBrief extends Resource
|
|||||||
{
|
{
|
||||||
public function toArray($request)
|
public function toArray($request)
|
||||||
{
|
{
|
||||||
return [
|
$data = [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'url' => url(route('api.flights.briefing', ['id' => $this->id])),
|
'url' => url(route('api.flights.briefing', ['id' => $this->id])),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!empty($this->fare_data)) {
|
||||||
|
$fares = [];
|
||||||
|
$fare_data = json_decode($this->fare_data, true);
|
||||||
|
foreach ($fare_data as $fare) {
|
||||||
|
$fares[] = new \App\Models\Fare($fare);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->aircraft->subfleet->fares = collect($fares);
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// Invalid fare data
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['subfleet'] = new Subfleet($this->aircraft->subfleet);
|
||||||
|
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,8 @@ class User extends Resource
|
|||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'pilot_id' => $this->pilot_id,
|
'pilot_id' => $this->pilot_id,
|
||||||
'ident' => $this->ident,
|
'ident' => $this->ident,
|
||||||
'name' => $this->name,
|
'name' => $this->name_private,
|
||||||
'name_private' => $this->name_private,
|
'name_private' => $this->name_private,
|
||||||
'email' => $this->email,
|
|
||||||
'avatar' => $this->resolveAvatarUrl(),
|
'avatar' => $this->resolveAvatarUrl(),
|
||||||
'rank_id' => $this->rank_id,
|
'rank_id' => $this->rank_id,
|
||||||
'home_airport' => $this->home_airport_id,
|
'home_airport' => $this->home_airport_id,
|
||||||
|
|||||||
@@ -20,12 +20,14 @@ class Fare extends Model
|
|||||||
public $table = 'fares';
|
public $table = 'fares';
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
'code',
|
'code',
|
||||||
'name',
|
'name',
|
||||||
'type',
|
'type',
|
||||||
'price',
|
'price',
|
||||||
'cost',
|
'cost',
|
||||||
'capacity',
|
'capacity',
|
||||||
|
'count',
|
||||||
'notes',
|
'notes',
|
||||||
'active',
|
'active',
|
||||||
];
|
];
|
||||||
@@ -34,6 +36,7 @@ class Fare extends Model
|
|||||||
'price' => 'float',
|
'price' => 'float',
|
||||||
'cost' => 'float',
|
'cost' => 'float',
|
||||||
'capacity' => 'integer',
|
'capacity' => 'integer',
|
||||||
|
'count' => 'integer',
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'active' => 'boolean',
|
'active' => 'boolean',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -305,7 +305,9 @@ class Pirep extends Model
|
|||||||
public function getFieldsAttribute()
|
public function getFieldsAttribute()
|
||||||
{
|
{
|
||||||
$custom_fields = PirepField::all();
|
$custom_fields = PirepField::all();
|
||||||
$field_values = PirepFieldValue::where('pirep_id', $this->id)->get();
|
$field_values = PirepFieldValue::where('pirep_id', $this->id)
|
||||||
|
->orderBy('created_at', 'asc')
|
||||||
|
->get();
|
||||||
|
|
||||||
// Merge the field values into $fields
|
// Merge the field values into $fields
|
||||||
foreach ($custom_fields as $field) {
|
foreach ($custom_fields as $field) {
|
||||||
@@ -321,7 +323,7 @@ class Pirep extends Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $field_values->sortBy('source');
|
return $field_values;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,11 +13,13 @@ use Illuminate\Support\Collection;
|
|||||||
* @property string $acars_xml
|
* @property string $acars_xml
|
||||||
* @property string $ofp_xml
|
* @property string $ofp_xml
|
||||||
* @property string $ofp_html
|
* @property string $ofp_html
|
||||||
|
* @property string $fare_data JSON string of the fare data that was generated
|
||||||
* @property Collection $images
|
* @property Collection $images
|
||||||
* @property Collection $files
|
* @property Collection $files
|
||||||
* @property Flight $flight
|
* @property Flight $flight
|
||||||
* @property User $user
|
* @property User $user
|
||||||
* @property SimBriefXML $xml
|
* @property SimBriefXML $xml
|
||||||
|
* @property Aircraft $aircraft
|
||||||
* @property string $acars_flightplan_url
|
* @property string $acars_flightplan_url
|
||||||
*/
|
*/
|
||||||
class SimBrief extends Model
|
class SimBrief extends Model
|
||||||
@@ -29,9 +31,11 @@ class SimBrief extends Model
|
|||||||
'id',
|
'id',
|
||||||
'user_id',
|
'user_id',
|
||||||
'flight_id',
|
'flight_id',
|
||||||
|
'aircraft_id',
|
||||||
'pirep_id',
|
'pirep_id',
|
||||||
'acars_xml',
|
'acars_xml',
|
||||||
'ofp_xml',
|
'ofp_xml',
|
||||||
|
'fare_data',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
];
|
];
|
||||||
@@ -80,6 +84,11 @@ class SimBrief extends Model
|
|||||||
* Relationships
|
* Relationships
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public function aircraft()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Aircraft::class, 'aircraft_id');
|
||||||
|
}
|
||||||
|
|
||||||
public function flight()
|
public function flight()
|
||||||
{
|
{
|
||||||
if (!empty($this->attributes['flight_id'])) {
|
if (!empty($this->attributes['flight_id'])) {
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ class BidService extends Service
|
|||||||
'flight',
|
'flight',
|
||||||
'flight.fares',
|
'flight.fares',
|
||||||
'flight.simbrief',
|
'flight.simbrief',
|
||||||
|
'flight.simbrief.aircraft',
|
||||||
'flight.subfleets',
|
'flight.subfleets',
|
||||||
'flight.subfleets.aircraft',
|
'flight.subfleets.aircraft',
|
||||||
'flight.subfleets.fares',
|
'flight.subfleets.fares',
|
||||||
|
|||||||
@@ -172,6 +172,24 @@ class FareService extends Service
|
|||||||
return $fare;
|
return $fare;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all the fares for an aircraft. check the pivot
|
||||||
|
* table to see if the price/cost/capacity has been overridden
|
||||||
|
* and return the correct amounts.
|
||||||
|
*
|
||||||
|
* @param Subfleet $subfleet
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getForSubfleet(Subfleet $subfleet)
|
||||||
|
{
|
||||||
|
$fares = $subfleet->fares->map(function ($fare) {
|
||||||
|
return $this->getFares($fare);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $fares;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach a fare to an flight
|
* Attach a fare to an flight
|
||||||
*
|
*
|
||||||
@@ -240,24 +258,6 @@ class FareService extends Service
|
|||||||
return $subfleet;
|
return $subfleet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* return all the fares for an aircraft. check the pivot
|
|
||||||
* table to see if the price/cost/capacity has been overridden
|
|
||||||
* and return the correct amounts.
|
|
||||||
*
|
|
||||||
* @param Subfleet $subfleet
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getForSubfleet(Subfleet $subfleet)
|
|
||||||
{
|
|
||||||
$fares = $subfleet->fares->map(function ($fare) {
|
|
||||||
return $this->getFares($fare);
|
|
||||||
});
|
|
||||||
|
|
||||||
return $fares;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the fare from a subfleet
|
* Delete the fare from a subfleet
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -29,11 +29,18 @@ class SimBriefService extends Service
|
|||||||
* @param string $user_id User who generated this
|
* @param string $user_id User who generated this
|
||||||
* @param string $ofp_id The SimBrief OFP ID
|
* @param string $ofp_id The SimBrief OFP ID
|
||||||
* @param string $flight_id The flight ID
|
* @param string $flight_id The flight ID
|
||||||
|
* @param string $ac_id The aircraft ID
|
||||||
|
* @param array $fares Full list of fares for the flightß
|
||||||
*
|
*
|
||||||
* @return SimBrief|null
|
* @return SimBrief|null
|
||||||
*/
|
*/
|
||||||
public function downloadOfp(string $user_id, string $ofp_id, string $flight_id)
|
public function downloadOfp(
|
||||||
{
|
string $user_id,
|
||||||
|
string $ofp_id,
|
||||||
|
string $flight_id,
|
||||||
|
string $ac_id,
|
||||||
|
array $fares = []
|
||||||
|
) {
|
||||||
$uri = str_replace('{id}', $ofp_id, config('phpvms.simbrief_url'));
|
$uri = str_replace('{id}', $ofp_id, config('phpvms.simbrief_url'));
|
||||||
|
|
||||||
$opts = [
|
$opts = [
|
||||||
@@ -57,11 +64,17 @@ class SimBriefService extends Service
|
|||||||
$ofp = simplexml_load_string($body, SimBriefXML::class);
|
$ofp = simplexml_load_string($body, SimBriefXML::class);
|
||||||
|
|
||||||
$attrs = [
|
$attrs = [
|
||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
'flight_id' => $flight_id,
|
'flight_id' => $flight_id,
|
||||||
'ofp_xml' => $ofp->asXML(),
|
'aircraft_id' => $ac_id,
|
||||||
|
'ofp_xml' => $ofp->asXML(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// encode the fares data to JSONß
|
||||||
|
if (!empty($fares)) {
|
||||||
|
$attrs['fare_data'] = json_encode($fares);
|
||||||
|
}
|
||||||
|
|
||||||
// Try to download the XML file for ACARS. If it doesn't work, try to modify the main OFP
|
// Try to download the XML file for ACARS. If it doesn't work, try to modify the main OFP
|
||||||
$acars_xml = $this->getAcarsOFP($ofp);
|
$acars_xml = $this->getAcarsOFP($ofp);
|
||||||
if (empty($acars_xml)) {
|
if (empty($acars_xml)) {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ let SBloop;
|
|||||||
|
|
||||||
let ofp_id;
|
let ofp_id;
|
||||||
let flight_id;
|
let flight_id;
|
||||||
|
let aircraft_id;
|
||||||
|
|
||||||
let outputpage_save;
|
let outputpage_save;
|
||||||
let outputpage_calc;
|
let outputpage_calc;
|
||||||
@@ -38,8 +39,9 @@ let timestamp;
|
|||||||
let api_code;
|
let api_code;
|
||||||
|
|
||||||
|
|
||||||
function simbriefsubmit(_flight_id, outputpage) {
|
function simbriefsubmit(_flight_id, _aircraft_id, outputpage) {
|
||||||
flight_id = _flight_id;
|
flight_id = _flight_id;
|
||||||
|
aircraft_id = _aircraft_id;
|
||||||
|
|
||||||
if (sbworker) {
|
if (sbworker) {
|
||||||
sbworker.close();
|
sbworker.close();
|
||||||
@@ -56,6 +58,10 @@ function simbriefsubmit(_flight_id, outputpage) {
|
|||||||
outputpage_save = null;
|
outputpage_save = null;
|
||||||
outputpage_calc = null;
|
outputpage_calc = null;
|
||||||
|
|
||||||
|
console.log('Flight ID', _flight_id);
|
||||||
|
console.log('Aircraft ID', _aircraft_id);
|
||||||
|
console.log('Output Page', outputpage);
|
||||||
|
|
||||||
do_simbriefsubmit(outputpage);
|
do_simbriefsubmit(outputpage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +93,7 @@ async function do_simbriefsubmit(outputpage) {
|
|||||||
data: {
|
data: {
|
||||||
api_req,
|
api_req,
|
||||||
flight_id,
|
flight_id,
|
||||||
|
aircraft_id,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -111,7 +118,6 @@ async function do_simbriefsubmit(outputpage) {
|
|||||||
input.setAttribute("value", api_code);
|
input.setAttribute("value", api_code);
|
||||||
apiform.appendChild(input);
|
apiform.appendChild(input);
|
||||||
|
|
||||||
|
|
||||||
var input = document.createElement("input");
|
var input = document.createElement("input");
|
||||||
input.setAttribute("type", "hidden");
|
input.setAttribute("type", "hidden");
|
||||||
input.setAttribute("name", "outputpage");
|
input.setAttribute("name", "outputpage");
|
||||||
@@ -184,6 +190,7 @@ async function Redirect_caller() {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: '/simbrief/check_ofp',
|
url: '/simbrief/check_ofp',
|
||||||
params: {
|
params: {
|
||||||
|
aircraft_id,
|
||||||
flight_id,
|
flight_id,
|
||||||
ofp_id,
|
ofp_id,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,49 +83,19 @@
|
|||||||
<h6><i class="fas fa-info-circle"></i> Configuration And Load Information For
|
<h6><i class="fas fa-info-circle"></i> Configuration And Load Information For
|
||||||
<b>{{ $aircraft->registration }} ({{ $aircraft->subfleet->name }})</b></h6>
|
<b>{{ $aircraft->registration }} ({{ $aircraft->subfleet->name }})</b></h6>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@php $loadarray = [] ; @endphp
|
@foreach($pax_load_sheet as $fare)
|
||||||
{{-- Generate Load Figures For Pax Fares --}}
|
<div class="col-sm-3">
|
||||||
@foreach($aircraft->subfleet->fares->where('type', 0) as $fare)
|
<label for="LoadFare{{ $fare['id'] }}">{{ $fare['name'] }} [Max: {{ $fare['capacity'] }}]</label>
|
||||||
@php
|
<input id="LoadFare{{ $fare['id'] }}" type="text" class="form-control" value="{{ $fare['count'] }}" disabled>
|
||||||
$randompaxperfare = floor(($fare->pivot->capacity * rand($loadmin, $loadmax)) /100);
|
</div>
|
||||||
$loadarray[] = ['LoadType' => $fare->code];
|
@endforeach
|
||||||
$loadarray[] = ['LoadFigure' => $randompaxperfare];
|
|
||||||
@endphp
|
|
||||||
<div class="col-sm-3">
|
|
||||||
<label for="LoadFare{{ $fare->id }}">{{ $fare->name }} [Max: {{ number_format($fare->pivot->capacity) }}]</label>
|
|
||||||
<input id="LoadFare{{ $fare->id }}" type="text" class="form-control" value="{{ number_format($randompaxperfare) }}" disabled>
|
|
||||||
</div>
|
|
||||||
@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 --}}
|
{{-- Generate Load Figures For Cargo Fares --}}
|
||||||
@foreach($aircraft->subfleet->fares->where('type', 1) as $fare)
|
@foreach($cargo_load_sheet as $fare)
|
||||||
@php
|
<div class="col-sm-3">
|
||||||
$randomcargoperfare = ceil((($fare->pivot->capacity - $tbagload) * rand($loadmin, $loadmax)) /100);
|
<label for="LoadFare{{ $fare['id'] }}">{{ $fare['name'] }} [Max: {{ number_format($fare['capacity'] - $tbagload) }} {{ setting('units.weight') }}]</label>
|
||||||
$loadarray[] = ['LoadType' => $fare->code];
|
<input id="LoadFare{{ $fare['id'] }}" type="text" class="form-control" value="{{ number_format($fare['count']) }}" disabled>
|
||||||
$loadarray[] = ['CargoFigure' => $randomcargoperfare];
|
</div>
|
||||||
@endphp
|
@endforeach
|
||||||
<div class="col-sm-3">
|
|
||||||
<label for="LoadFare{{ $fare->id }}">{{ $fare->name }} [Max: {{ number_format($fare->pivot->capacity - $tbagload) }} {{ setting('units.weight') }}]</label>
|
|
||||||
<input id="LoadFare{{ $fare->id }}" type="text" class="form-control" value="{{ number_format($randomcargoperfare) }}" disabled>
|
|
||||||
</div>
|
|
||||||
@endforeach
|
|
||||||
@php
|
|
||||||
$loadcollection = collect($loadarray);
|
|
||||||
$tcargoload = $loadcollection->sum('CargoFigure');
|
|
||||||
$tpayload = $tpaxload + $tbagload + $tcargoload;
|
|
||||||
@endphp
|
|
||||||
</div>
|
</div>
|
||||||
@if(isset($tpayload) && $tpayload > 0)
|
@if(isset($tpayload) && $tpayload > 0)
|
||||||
{{-- Display The Weights Generated --}}
|
{{-- Display The Weights Generated --}}
|
||||||
@@ -166,33 +136,13 @@
|
|||||||
@if($tcargoload)
|
@if($tcargoload)
|
||||||
<input type='hidden' name='cargo' value="{{ number_format(($tcargoload / 1000),1) }}">
|
<input type='hidden' name='cargo' value="{{ number_format(($tcargoload / 1000),1) }}">
|
||||||
@endif
|
@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)
|
@if(isset($tpayload) && $tpayload > 0)
|
||||||
@php
|
<input type="hidden" name="manualrmk" value="Load Distribution {{ $loaddist }}">
|
||||||
$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
|
|
||||||
<input type="hidden" name="manualrmk" value="{{ $loaddisttxt }}{{ $loaddist }}">
|
|
||||||
@endif
|
@endif
|
||||||
<input type="hidden" name="airline" value="{{ $flight->airline->icao }}">
|
<input type="hidden" name="airline" value="{{ $flight->airline->icao }}">
|
||||||
<input type="hidden" name="fltnum" value="{{ $flight->flight_number }}">
|
<input type="hidden" name="fltnum" value="{{ $flight->flight_number }}">
|
||||||
@if(setting('simbrief.callsign', false))
|
@if(setting('simbrief.callsign', true))
|
||||||
<input type="hidden" name="callsign" value="{{ Auth::user()->ident }}">
|
<input type="hidden" name="callsign" value="{{ $user->ident }}">
|
||||||
@endif
|
@endif
|
||||||
<input type="hidden" id="steh" name="steh" maxlength="2">
|
<input type="hidden" id="steh" name="steh" maxlength="2">
|
||||||
<input type="hidden" id="stem" name="stem" maxlength="2">
|
<input type="hidden" id="stem" name="stem" maxlength="2">
|
||||||
@@ -351,8 +301,8 @@
|
|||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="button"
|
<input type="button"
|
||||||
onclick="simbriefsubmit('{{ $flight->id }}', '{{ url(route('frontend.simbrief.briefing', [''])) }}');"
|
onclick="simbriefsubmit('{{ $flight->id }}', '{{ $aircraft->id }}', '{{ url(route('frontend.simbrief.briefing', [''])) }}');"
|
||||||
class="btn btn-primary" value="Generate">
|
class="btn btn-primary" value="Generate">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -70,11 +70,22 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12 text-right">
|
<div class="col-sm-12 text-right">
|
||||||
|
<!-- Simbrief enabled -->
|
||||||
@if ($simbrief !== false)
|
@if ($simbrief !== false)
|
||||||
|
|
||||||
|
<!-- Show button if the bids-only is disable, or if bids-only is enabled, they've saved it -->
|
||||||
@if ($simbrief_bids === false || ($simbrief_bids === true && in_array($flight->id, $saved, true)))
|
@if ($simbrief_bids === false || ($simbrief_bids === true && in_array($flight->id, $saved, true)))
|
||||||
<a href="{{ route('frontend.simbrief.generate') }}?flight_id={{ $flight->id }}"
|
<a href="{{ route('frontend.simbrief.generate') }}?flight_id={{ $flight->id }}"
|
||||||
class="btn btn-sm btn-outline-primary">
|
class="btn btn-sm btn-outline-primary">
|
||||||
Create SimBrief Flight Plan
|
Create Simbrief Flight Plan
|
||||||
|
</a>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<!-- If this flight has a briefing, show the link to view it-->
|
||||||
|
@if ($flight->simbrief)
|
||||||
|
<a href="{{ route('frontend.simbrief.briefing', $flight->simbrief->id) }}"
|
||||||
|
class="btn btn-sm btn-outline-primary">
|
||||||
|
View Simbrief Flight Plan
|
||||||
</a>
|
</a>
|
||||||
@endif
|
@endif
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<div class="col">
|
<div class="col">
|
||||||
{{Form::label('fare_'.$fare->id, $fare->name.' ('. \App\Models\Enums\FareType::label($fare->type).', code '.$fare->code.')')}}
|
{{Form::label('fare_'.$fare->id, $fare->name.' ('. \App\Models\Enums\FareType::label($fare->type).', code '.$fare->code.')')}}
|
||||||
<div class="input-group form-group">
|
<div class="input-group form-group">
|
||||||
{{ Form::number('fare_'.$fare->id, null, ['class' => 'form-control', 'min' => 0]) }}
|
{{ Form::number('fare_'.$fare->id, $fare->count, ['class' => 'form-control', 'min' => 0]) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,7 +3,10 @@
|
|||||||
namespace Tests;
|
namespace Tests;
|
||||||
|
|
||||||
use App\Models\Acars;
|
use App\Models\Acars;
|
||||||
|
use App\Models\Aircraft;
|
||||||
use App\Models\Enums\AcarsType;
|
use App\Models\Enums\AcarsType;
|
||||||
|
use App\Models\Enums\FareType;
|
||||||
|
use App\Models\Enums\UserState;
|
||||||
use App\Models\Flight;
|
use App\Models\Flight;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
use App\Models\SimBrief;
|
use App\Models\SimBrief;
|
||||||
@@ -16,14 +19,42 @@ class SimBriefTest extends TestCase
|
|||||||
{
|
{
|
||||||
private static $simbrief_flight_id = 'simbriefflightid';
|
private static $simbrief_flight_id = 'simbriefflightid';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $attrs Additional user attributes
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function createUserData(array $attrs = []): array
|
||||||
|
{
|
||||||
|
$subfleet = $this->createSubfleetWithAircraft(1);
|
||||||
|
$rank = $this->createRank(2, [$subfleet['subfleet']->id]);
|
||||||
|
|
||||||
|
/** @var User $user */
|
||||||
|
$user = factory(User::class)->create(array_merge([
|
||||||
|
'flight_time' => 1000,
|
||||||
|
'rank_id' => $rank->id,
|
||||||
|
'state' => UserState::ACTIVE,
|
||||||
|
], $attrs));
|
||||||
|
|
||||||
|
return [
|
||||||
|
'subfleet' => $subfleet['subfleet'],
|
||||||
|
'aircraft' => $subfleet['aircraft'],
|
||||||
|
'user' => $user,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load SimBrief
|
* Load SimBrief
|
||||||
*
|
*
|
||||||
* @param \App\Models\User $user
|
* @param \App\Models\User $user
|
||||||
|
* @param \App\Models\Aircraft|null $aircraft
|
||||||
|
* @param array $fares
|
||||||
*
|
*
|
||||||
* @return \App\Models\SimBrief
|
* @return \App\Models\SimBrief
|
||||||
*/
|
*/
|
||||||
protected function loadSimBrief(User $user): SimBrief
|
protected function loadSimBrief(User $user, Aircraft $aircraft, $fares = []): SimBrief
|
||||||
{
|
{
|
||||||
/** @var \App\Models\Flight $flight */
|
/** @var \App\Models\Flight $flight */
|
||||||
$flight = factory(Flight::class)->create([
|
$flight = factory(Flight::class)->create([
|
||||||
@@ -40,7 +71,7 @@ class SimBriefTest extends TestCase
|
|||||||
/** @var SimBriefService $sb */
|
/** @var SimBriefService $sb */
|
||||||
$sb = app(SimBriefService::class);
|
$sb = app(SimBriefService::class);
|
||||||
|
|
||||||
return $sb->downloadOfp($user->id, Utils::generateNewId(), $flight->id);
|
return $sb->downloadOfp($user->id, Utils::generateNewId(), $flight->id, $aircraft->id, $fares);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,8 +79,9 @@ class SimBriefTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testReadSimbrief()
|
public function testReadSimbrief()
|
||||||
{
|
{
|
||||||
$this->user = $this->createUser();
|
$userinfo = $this->createUserData();
|
||||||
$briefing = $this->loadSimBrief($this->user);
|
$this->user = $userinfo['user'];
|
||||||
|
$briefing = $this->loadSimBrief($this->user, $userinfo['aircraft']->first(), []);
|
||||||
|
|
||||||
$this->assertNotEmpty($briefing->ofp_xml);
|
$this->assertNotEmpty($briefing->ofp_xml);
|
||||||
$this->assertNotNull($briefing->xml);
|
$this->assertNotNull($briefing->xml);
|
||||||
@@ -87,8 +119,18 @@ class SimBriefTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testApiCalls()
|
public function testApiCalls()
|
||||||
{
|
{
|
||||||
$this->user = $this->createUser();
|
$userinfo = $this->createUserData();
|
||||||
$briefing = $this->loadSimBrief($this->user);
|
$this->user = $userinfo['user'];
|
||||||
|
$briefing = $this->loadSimBrief($this->user, $userinfo['aircraft']->first(), [
|
||||||
|
[
|
||||||
|
'id' => 100,
|
||||||
|
'code' => 'F',
|
||||||
|
'name' => 'Test Fare',
|
||||||
|
'type' => 'P',
|
||||||
|
'capacity' => 100,
|
||||||
|
'count' => 99,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
// Check the flight API response
|
// Check the flight API response
|
||||||
$response = $this->get('/api/flights/'.$briefing->flight_id);
|
$response = $this->get('/api/flights/'.$briefing->flight_id);
|
||||||
@@ -120,8 +162,20 @@ class SimBriefTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUserBidSimbrief()
|
public function testUserBidSimbrief()
|
||||||
{
|
{
|
||||||
$this->user = $this->createUser();
|
$fares = [
|
||||||
$this->loadSimBrief($this->user);
|
[
|
||||||
|
'id' => 100,
|
||||||
|
'code' => 'F',
|
||||||
|
'name' => 'Test Fare',
|
||||||
|
'type' => FareType::PASSENGER,
|
||||||
|
'capacity' => 100,
|
||||||
|
'count' => 99,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$userinfo = $this->createUserData();
|
||||||
|
$this->user = $userinfo['user'];
|
||||||
|
$this->loadSimBrief($this->user, $userinfo['aircraft']->first(), $fares);
|
||||||
|
|
||||||
// Find the flight
|
// Find the flight
|
||||||
$uri = '/api/user/bids';
|
$uri = '/api/user/bids';
|
||||||
@@ -132,18 +186,35 @@ class SimBriefTest extends TestCase
|
|||||||
|
|
||||||
// Make sure Simbrief is there
|
// Make sure Simbrief is there
|
||||||
$this->assertNotNull($body['flight']['simbrief']['id']);
|
$this->assertNotNull($body['flight']['simbrief']['id']);
|
||||||
|
$this->assertNotNull($body['flight']['simbrief']['subfleet']['fares']);
|
||||||
|
|
||||||
|
$subfleet = $body['flight']['simbrief']['subfleet'];
|
||||||
|
$this->assertEquals($fares[0]['id'], $subfleet['fares'][0]['id']);
|
||||||
|
$this->assertEquals($fares[0]['count'], $subfleet['fares'][0]['count']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAttachToPirep()
|
public function testAttachToPirep()
|
||||||
{
|
{
|
||||||
$user = $this->createUser();
|
$userinfo = $this->createUserData();
|
||||||
|
$this->user = $userinfo['user'];
|
||||||
|
|
||||||
|
/** @var Pirep $pirep */
|
||||||
$pirep = factory(Pirep::class)->create([
|
$pirep = factory(Pirep::class)->create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $this->user->id,
|
||||||
'dpt_airport_id' => 'OMAA',
|
'dpt_airport_id' => 'OMAA',
|
||||||
'arr_airport_id' => 'OMDB',
|
'arr_airport_id' => 'OMDB',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$briefing = $this->loadSimBrief($user);
|
$briefing = $this->loadSimBrief($this->user, $userinfo['aircraft']->first(), [
|
||||||
|
[
|
||||||
|
'id' => 100,
|
||||||
|
'code' => 'F',
|
||||||
|
'name' => 'Test Fare',
|
||||||
|
'type' => 'P',
|
||||||
|
'capacity' => 100,
|
||||||
|
'count' => 99,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
/** @var SimBriefService $sb */
|
/** @var SimBriefService $sb */
|
||||||
$sb = app(SimBriefService::class);
|
$sb = app(SimBriefService::class);
|
||||||
@@ -172,7 +243,9 @@ class SimBriefTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testClearExpiredBriefs()
|
public function testClearExpiredBriefs()
|
||||||
{
|
{
|
||||||
$user = $this->createUser();
|
$userinfo = $this->createUserData();
|
||||||
|
$user = $userinfo['user'];
|
||||||
|
|
||||||
$sb_ignored = factory(SimBrief::class)->create([
|
$sb_ignored = factory(SimBrief::class)->create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'flight_id' => 'a_flight_id',
|
'flight_id' => 'a_flight_id',
|
||||||
|
|||||||
Reference in New Issue
Block a user