specify fares, js to dynamically change fare form; get applicable fares for the flight/pirep #125
This commit is contained in:
parent
910c0e0eab
commit
58e0f50c48
@ -60,30 +60,15 @@ class CreatePirepTables extends Migration
|
|||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
* Financial tables/fields
|
|
||||||
*/
|
|
||||||
Schema::create('pirep_expenses', function (Blueprint $table) {
|
|
||||||
$table->bigIncrements('id');
|
|
||||||
$table->string('pirep_id', \App\Models\Pirep::ID_MAX_LENGTH);
|
|
||||||
$table->string('name');
|
|
||||||
$table->double('value')->nullable();
|
|
||||||
|
|
||||||
$table->index('pirep_id');
|
|
||||||
});
|
|
||||||
|
|
||||||
Schema::create('pirep_fares', function (Blueprint $table) {
|
Schema::create('pirep_fares', function (Blueprint $table) {
|
||||||
$table->bigIncrements('id');
|
$table->bigIncrements('id');
|
||||||
$table->string('pirep_id', \App\Models\Pirep::ID_MAX_LENGTH);
|
$table->string('pirep_id', \App\Models\Pirep::ID_MAX_LENGTH);
|
||||||
$table->unsignedBigInteger('fare_id');
|
$table->unsignedInteger('fare_id');
|
||||||
$table->unsignedInteger('count')->nullable();
|
$table->unsignedInteger('count')->nullable();
|
||||||
|
|
||||||
$table->index('pirep_id');
|
$table->index('pirep_id');
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
* Additional PIREP data
|
|
||||||
*/
|
|
||||||
Schema::create('pirep_fields', function (Blueprint $table) {
|
Schema::create('pirep_fields', function (Blueprint $table) {
|
||||||
$table->bigIncrements('id');
|
$table->bigIncrements('id');
|
||||||
$table->string('name', 50);
|
$table->string('name', 50);
|
||||||
@ -95,6 +80,7 @@ class CreatePirepTables extends Migration
|
|||||||
$table->bigIncrements('id');
|
$table->bigIncrements('id');
|
||||||
$table->string('pirep_id', \App\Models\Pirep::ID_MAX_LENGTH);
|
$table->string('pirep_id', \App\Models\Pirep::ID_MAX_LENGTH);
|
||||||
$table->string('name', 50);
|
$table->string('name', 50);
|
||||||
|
$table->string('slug', 50)->nullable();
|
||||||
$table->string('value')->nullable();
|
$table->string('value')->nullable();
|
||||||
$table->string('source')->nullable();
|
$table->string('source')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
@ -112,7 +98,6 @@ class CreatePirepTables extends Migration
|
|||||||
{
|
{
|
||||||
Schema::dropIfExists('pireps');
|
Schema::dropIfExists('pireps');
|
||||||
Schema::dropIfExists('pirep_comments');
|
Schema::dropIfExists('pirep_comments');
|
||||||
Schema::dropIfExists('pirep_expenses');
|
|
||||||
Schema::dropIfExists('pirep_fares');
|
Schema::dropIfExists('pirep_fares');
|
||||||
Schema::dropIfExists('pirep_fields');
|
Schema::dropIfExists('pirep_fields');
|
||||||
Schema::dropIfExists('pirep_field_values');
|
Schema::dropIfExists('pirep_field_values');
|
||||||
|
@ -353,7 +353,14 @@ pirep_field_values:
|
|||||||
- id: 1
|
- id: 1
|
||||||
pirep_id: pirepid_1
|
pirep_id: pirepid_1
|
||||||
name: arrival gate
|
name: arrival gate
|
||||||
value: B14
|
slug: arrival_gate
|
||||||
|
value: 10
|
||||||
|
source: manual
|
||||||
|
- id: 2
|
||||||
|
pirep_id: pirepid_1
|
||||||
|
name: departure gate
|
||||||
|
slug: departure_gate
|
||||||
|
value: B32
|
||||||
source: manual
|
source: manual
|
||||||
|
|
||||||
pirep_comments:
|
pirep_comments:
|
||||||
|
@ -66,7 +66,7 @@ class Handler extends ExceptionHandler
|
|||||||
*/
|
*/
|
||||||
public function render($request, Exception $exception)
|
public function render($request, Exception $exception)
|
||||||
{
|
{
|
||||||
if ($request->expectsJson() || $request->is('api/*')) {
|
if ($request->is('api/*')) {
|
||||||
|
|
||||||
$headers = [];
|
$headers = [];
|
||||||
|
|
||||||
|
@ -5,11 +5,14 @@ namespace App\Http\Controllers\Admin;
|
|||||||
use App\Facades\Utils;
|
use App\Facades\Utils;
|
||||||
use App\Http\Requests\CreatePirepRequest;
|
use App\Http\Requests\CreatePirepRequest;
|
||||||
use App\Http\Requests\UpdatePirepRequest;
|
use App\Http\Requests\UpdatePirepRequest;
|
||||||
|
use App\Models\Enums\PirepSource;
|
||||||
use App\Models\Enums\PirepState;
|
use App\Models\Enums\PirepState;
|
||||||
|
use App\Models\Pirep;
|
||||||
use App\Models\PirepComment;
|
use App\Models\PirepComment;
|
||||||
use App\Repositories\AircraftRepository;
|
use App\Repositories\AircraftRepository;
|
||||||
use App\Repositories\AirlineRepository;
|
use App\Repositories\AirlineRepository;
|
||||||
use App\Repositories\AirportRepository;
|
use App\Repositories\AirportRepository;
|
||||||
|
use App\Repositories\PirepFieldRepository;
|
||||||
use App\Repositories\PirepRepository;
|
use App\Repositories\PirepRepository;
|
||||||
use App\Repositories\SubfleetRepository;
|
use App\Repositories\SubfleetRepository;
|
||||||
use App\Services\PIREPService;
|
use App\Services\PIREPService;
|
||||||
@ -30,6 +33,7 @@ class PirepController extends BaseController
|
|||||||
$aircraftRepo,
|
$aircraftRepo,
|
||||||
$pirepSvc,
|
$pirepSvc,
|
||||||
$pirepRepo,
|
$pirepRepo,
|
||||||
|
$pirepFieldRepo,
|
||||||
$subfleetRepo,
|
$subfleetRepo,
|
||||||
$userSvc;
|
$userSvc;
|
||||||
|
|
||||||
@ -48,6 +52,7 @@ class PirepController extends BaseController
|
|||||||
AirlineRepository $airlineRepo,
|
AirlineRepository $airlineRepo,
|
||||||
AircraftRepository $aircraftRepo,
|
AircraftRepository $aircraftRepo,
|
||||||
PirepRepository $pirepRepo,
|
PirepRepository $pirepRepo,
|
||||||
|
PirepFieldRepository $pirepFieldRepo,
|
||||||
PIREPService $pirepSvc,
|
PIREPService $pirepSvc,
|
||||||
SubfleetRepository $subfleetRepo,
|
SubfleetRepository $subfleetRepo,
|
||||||
UserService $userSvc
|
UserService $userSvc
|
||||||
@ -56,6 +61,7 @@ class PirepController extends BaseController
|
|||||||
$this->airlineRepo = $airlineRepo;
|
$this->airlineRepo = $airlineRepo;
|
||||||
$this->aircraftRepo = $aircraftRepo;
|
$this->aircraftRepo = $aircraftRepo;
|
||||||
$this->pirepRepo = $pirepRepo;
|
$this->pirepRepo = $pirepRepo;
|
||||||
|
$this->pirepFieldRepo = $pirepFieldRepo;
|
||||||
$this->pirepSvc = $pirepSvc;
|
$this->pirepSvc = $pirepSvc;
|
||||||
$this->subfleetRepo = $subfleetRepo;
|
$this->subfleetRepo = $subfleetRepo;
|
||||||
$this->userSvc = $userSvc;
|
$this->userSvc = $userSvc;
|
||||||
@ -88,6 +94,77 @@ class PirepController extends BaseController
|
|||||||
return $aircraft;
|
return $aircraft;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save any custom fields found
|
||||||
|
* @param Pirep $pirep
|
||||||
|
* @param Request $request
|
||||||
|
*/
|
||||||
|
protected function saveCustomFields(Pirep $pirep, Request $request)
|
||||||
|
{
|
||||||
|
$custom_fields = [];
|
||||||
|
$pirep_fields = $this->pirepFieldRepo->all();
|
||||||
|
foreach ($pirep_fields as $field) {
|
||||||
|
if (!$request->filled($field->slug)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$custom_fields[] = [
|
||||||
|
'name' => $field->name,
|
||||||
|
'value' => $request->input($field->slug),
|
||||||
|
'source' => PirepSource::MANUAL
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::info('PIREP Custom Fields', $custom_fields);
|
||||||
|
$this->pirepSvc->updateCustomFields($pirep->id, $custom_fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the fares that have been specified/saved
|
||||||
|
* @param Pirep $pirep
|
||||||
|
* @param Request $request
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
protected function saveFares(Pirep $pirep, Request $request)
|
||||||
|
{
|
||||||
|
$fares = [];
|
||||||
|
foreach ($pirep->aircraft->subfleet->fares as $fare) {
|
||||||
|
|
||||||
|
$field_name = 'fare_' . $fare->id;
|
||||||
|
if (!$request->filled($field_name)) {
|
||||||
|
$count = 0;
|
||||||
|
} else {
|
||||||
|
$count = $request->input($field_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fares[] = [
|
||||||
|
'fare_id' => $fare->id,
|
||||||
|
'count' => $count,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pirepSvc->saveFares($pirep->id, $fares);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the fares form for a given aircraft
|
||||||
|
* @param Request $request
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
*/
|
||||||
|
public function fares(Request $request)
|
||||||
|
{
|
||||||
|
$aircraft_id = $request->input('aircraft_id');
|
||||||
|
Log::info($aircraft_id);
|
||||||
|
|
||||||
|
$aircraft = $this->aircraftRepo->find($aircraft_id);
|
||||||
|
Log::info('aircraft', $aircraft->toArray());
|
||||||
|
|
||||||
|
return view('admin.pireps.fares', [
|
||||||
|
'aircraft' => $aircraft,
|
||||||
|
'read_only' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
@ -144,6 +221,7 @@ class PirepController extends BaseController
|
|||||||
* @param CreatePirepRequest $request
|
* @param CreatePirepRequest $request
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function store(CreatePirepRequest $request)
|
public function store(CreatePirepRequest $request)
|
||||||
{
|
{
|
||||||
@ -154,6 +232,9 @@ class PirepController extends BaseController
|
|||||||
$minutes = (int) $attrs['minutes'];
|
$minutes = (int) $attrs['minutes'];
|
||||||
$pirep->flight_time = Utils::hoursToMinutes($hours) + $minutes;
|
$pirep->flight_time = Utils::hoursToMinutes($hours) + $minutes;
|
||||||
|
|
||||||
|
$this->saveCustomFields($pirep, $request);
|
||||||
|
$this->saveFares($pirep, $request);
|
||||||
|
|
||||||
Flash::success('Pirep saved successfully.');
|
Flash::success('Pirep saved successfully.');
|
||||||
return redirect(route('admin.pireps.index'));
|
return redirect(route('admin.pireps.index'));
|
||||||
}
|
}
|
||||||
@ -195,17 +276,26 @@ class PirepController extends BaseController
|
|||||||
$pirep->minutes = $time->minutes;
|
$pirep->minutes = $time->minutes;
|
||||||
|
|
||||||
# Can we modify?
|
# Can we modify?
|
||||||
$read_only = false;
|
$read_only = $pirep->state !== PirepState::PENDING;
|
||||||
if($pirep->state !== PirepState::PENDING) {
|
|
||||||
$read_only = false;
|
# set the custom fields
|
||||||
|
foreach ($pirep->fields as $field) {
|
||||||
|
$pirep->{$field->slug} = $field->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
# set the fares
|
||||||
|
foreach ($pirep->fares as $fare) {
|
||||||
|
$field_name = 'fare_' . $fare->fare_id;
|
||||||
|
$pirep->{$field_name} = $fare->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin.pireps.edit', [
|
return view('admin.pireps.edit', [
|
||||||
'pirep' => $pirep,
|
'pirep' => $pirep,
|
||||||
'read_only' => $read_only,
|
'read_only' => $read_only,
|
||||||
'aircraft' => $this->aircraftList(),
|
'aircraft' => $pirep->aircraft,
|
||||||
'airports' => $this->airportRepo->selectBoxList(),
|
'aircraft_list' => $this->aircraftList(),
|
||||||
'airlines' => $this->airlineRepo->selectBoxList(),
|
'airports_list' => $this->airportRepo->selectBoxList(),
|
||||||
|
'airlines_list' => $this->airlineRepo->selectBoxList(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,6 +332,9 @@ class PirepController extends BaseController
|
|||||||
$this->pirepSvc->saveRoute($pirep);
|
$this->pirepSvc->saveRoute($pirep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->saveCustomFields($pirep, $request);
|
||||||
|
$this->saveFares($pirep, $request);
|
||||||
|
|
||||||
Flash::success('Pirep updated successfully.');
|
Flash::success('Pirep updated successfully.');
|
||||||
return redirect(route('admin.pireps.index'));
|
return redirect(route('admin.pireps.index'));
|
||||||
}
|
}
|
||||||
|
@ -5,20 +5,21 @@ namespace App\Http\Controllers\Frontend;
|
|||||||
use App\Facades\Utils;
|
use App\Facades\Utils;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\CreatePirepRequest;
|
use App\Http\Requests\CreatePirepRequest;
|
||||||
use App\Models\Enums\AcarsType;
|
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\Pirep;
|
use App\Models\Pirep;
|
||||||
use App\Repositories\AcarsRepository;
|
use App\Repositories\AircraftRepository;
|
||||||
use App\Repositories\AirlineRepository;
|
use App\Repositories\AirlineRepository;
|
||||||
use App\Repositories\AirportRepository;
|
use App\Repositories\AirportRepository;
|
||||||
use App\Repositories\Criteria\WhereCriteria;
|
use App\Repositories\Criteria\WhereCriteria;
|
||||||
use App\Repositories\PirepFieldRepository;
|
use App\Repositories\PirepFieldRepository;
|
||||||
use App\Repositories\PirepRepository;
|
use App\Repositories\PirepRepository;
|
||||||
use App\Repositories\SubfleetRepository;
|
|
||||||
use App\Services\GeoService;
|
use App\Services\GeoService;
|
||||||
use App\Services\PIREPService;
|
use App\Services\PIREPService;
|
||||||
use App\Services\UserService;
|
use App\Services\UserService;
|
||||||
|
use App\Support\Units\Time;
|
||||||
|
use Flash;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Log;
|
use Log;
|
||||||
@ -26,40 +27,40 @@ use Log;
|
|||||||
|
|
||||||
class PirepController extends Controller
|
class PirepController extends Controller
|
||||||
{
|
{
|
||||||
private $airlineRepo,
|
private $aircraftRepo,
|
||||||
|
$airlineRepo,
|
||||||
$pirepRepo,
|
$pirepRepo,
|
||||||
$airportRepo,
|
$airportRepo,
|
||||||
$pirepFieldRepo,
|
$pirepFieldRepo,
|
||||||
$geoSvc,
|
$geoSvc,
|
||||||
$pirepSvc,
|
$pirepSvc,
|
||||||
$subfleetRepo,
|
|
||||||
$userSvc;
|
$userSvc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PirepController constructor.
|
* PirepController constructor.
|
||||||
|
* @param AircraftRepository $aircraftRepo
|
||||||
* @param AirlineRepository $airlineRepo
|
* @param AirlineRepository $airlineRepo
|
||||||
* @param PirepRepository $pirepRepo
|
|
||||||
* @param AirportRepository $airportRepo
|
* @param AirportRepository $airportRepo
|
||||||
|
* @param PirepRepository $pirepRepo
|
||||||
* @param PirepFieldRepository $pirepFieldRepo
|
* @param PirepFieldRepository $pirepFieldRepo
|
||||||
* @param GeoService $geoSvc
|
* @param GeoService $geoSvc
|
||||||
* @param SubfleetRepository $subfleetRepo
|
|
||||||
* @param PIREPService $pirepSvc
|
* @param PIREPService $pirepSvc
|
||||||
* @param UserService $userSvc
|
* @param UserService $userSvc
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
AircraftRepository $aircraftRepo,
|
||||||
AirlineRepository $airlineRepo,
|
AirlineRepository $airlineRepo,
|
||||||
PirepRepository $pirepRepo,
|
|
||||||
AirportRepository $airportRepo,
|
AirportRepository $airportRepo,
|
||||||
|
PirepRepository $pirepRepo,
|
||||||
PirepFieldRepository $pirepFieldRepo,
|
PirepFieldRepository $pirepFieldRepo,
|
||||||
GeoService $geoSvc,
|
GeoService $geoSvc,
|
||||||
SubfleetRepository $subfleetRepo,
|
|
||||||
PIREPService $pirepSvc,
|
PIREPService $pirepSvc,
|
||||||
UserService $userSvc
|
UserService $userSvc
|
||||||
) {
|
) {
|
||||||
|
$this->aircraftRepo = $aircraftRepo;
|
||||||
$this->airlineRepo = $airlineRepo;
|
$this->airlineRepo = $airlineRepo;
|
||||||
$this->pirepRepo = $pirepRepo;
|
$this->pirepRepo = $pirepRepo;
|
||||||
$this->airportRepo = $airportRepo;
|
$this->airportRepo = $airportRepo;
|
||||||
$this->subfleetRepo = $subfleetRepo;
|
|
||||||
$this->pirepFieldRepo = $pirepFieldRepo;
|
$this->pirepFieldRepo = $pirepFieldRepo;
|
||||||
|
|
||||||
$this->geoSvc = $geoSvc;
|
$this->geoSvc = $geoSvc;
|
||||||
@ -93,6 +94,58 @@ class PirepController extends Controller
|
|||||||
return $aircraft;
|
return $aircraft;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save any custom fields found
|
||||||
|
* @param Pirep $pirep
|
||||||
|
* @param Request $request
|
||||||
|
*/
|
||||||
|
protected function saveCustomFields(Pirep $pirep, Request $request)
|
||||||
|
{
|
||||||
|
$custom_fields = [];
|
||||||
|
$pirep_fields = $this->pirepFieldRepo->all();
|
||||||
|
foreach ($pirep_fields as $field) {
|
||||||
|
if (!$request->filled($field->slug)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$custom_fields[] = [
|
||||||
|
'name' => $field->name,
|
||||||
|
'value' => $request->input($field->slug),
|
||||||
|
'source' => PirepSource::MANUAL
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::info('PIREP Custom Fields', $custom_fields);
|
||||||
|
$this->pirepSvc->updateCustomFields($pirep->id, $custom_fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the fares that have been specified/saved
|
||||||
|
* @param Pirep $pirep
|
||||||
|
* @param Request $request
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
protected function saveFares(Pirep $pirep, Request $request)
|
||||||
|
{
|
||||||
|
$fares = [];
|
||||||
|
foreach($pirep->aircraft->subfleet->fares as $fare) {
|
||||||
|
|
||||||
|
$field_name = 'fare_'.$fare->id;
|
||||||
|
if(!$request->filled($field_name)) {
|
||||||
|
$count = 0;
|
||||||
|
} else {
|
||||||
|
$count = $request->input($field_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fares[] = [
|
||||||
|
'fare_id' => $fare->id,
|
||||||
|
'count' => $count,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pirepSvc->saveFares($pirep->id, $fares);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
@ -114,14 +167,56 @@ class PirepController extends Controller
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function show($id)
|
||||||
|
{
|
||||||
|
$pirep = $this->pirepRepo->find($id);
|
||||||
|
if (empty($pirep)) {
|
||||||
|
Flash::error('Pirep not found');
|
||||||
|
return redirect(route('frontend.pirep.index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$map_features = $this->geoSvc->pirepGeoJson($pirep);
|
||||||
|
|
||||||
|
return $this->view('pireps.show', [
|
||||||
|
'pirep' => $pirep,
|
||||||
|
'map_features' => $map_features,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the fares form for a given aircraft
|
||||||
|
* @param Request $request
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
*/
|
||||||
|
public function fares(Request $request)
|
||||||
|
{
|
||||||
|
$aircraft_id = $request->input('aircraft_id');
|
||||||
|
$aircraft = $this->aircraftRepo->find($aircraft_id);
|
||||||
|
|
||||||
|
return $this->view('pireps.fares', [
|
||||||
|
'aircraft' => $aircraft,
|
||||||
|
'read_only' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new flight report
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
*/
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
|
|
||||||
return $this->view('pireps.create', [
|
return $this->view('pireps.create', [
|
||||||
'airlines' => $this->airlineRepo->selectBoxList(true),
|
'aircraft' => null,
|
||||||
'aircraft' => $this->aircraftList($user, true),
|
'read_only' => false,
|
||||||
'airports' => $this->airportRepo->selectBoxList(true),
|
'airline_list' => $this->airlineRepo->selectBoxList(true),
|
||||||
|
'aircraft_list' => $this->aircraftList($user, true),
|
||||||
|
'airport_list' => $this->airportRepo->selectBoxList(true),
|
||||||
'pirep_fields' => $this->pirepFieldRepo->all(),
|
'pirep_fields' => $this->pirepFieldRepo->all(),
|
||||||
'field_values' => [],
|
'field_values' => [],
|
||||||
]);
|
]);
|
||||||
@ -150,45 +245,92 @@ class PirepController extends Controller
|
|||||||
$minutes = (int) $request->input('minutes', 0);
|
$minutes = (int) $request->input('minutes', 0);
|
||||||
$pirep->flight_time = Utils::hoursToMinutes($hours) + $minutes;
|
$pirep->flight_time = Utils::hoursToMinutes($hours) + $minutes;
|
||||||
|
|
||||||
// The custom fields from the form
|
$pirep = $this->pirepSvc->create($pirep);
|
||||||
$custom_fields = [];
|
$this->saveCustomFields($pirep, $request);
|
||||||
$pirep_fields = $this->pirepFieldRepo->all();
|
$this->saveFares($pirep, $request);
|
||||||
foreach ($pirep_fields as $field) {
|
|
||||||
if(!$request->filled($field->slug)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$custom_fields[] = [
|
|
||||||
'name' => $field->name,
|
|
||||||
'value' => $request->input($field->slug),
|
|
||||||
'source' => PirepSource::MANUAL
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::info('PIREP Custom Fields', $custom_fields);
|
|
||||||
$pirep = $this->pirepSvc->create($pirep, $custom_fields);
|
|
||||||
$this->pirepSvc->saveRoute($pirep);
|
$this->pirepSvc->saveRoute($pirep);
|
||||||
|
|
||||||
return redirect(route('frontend.pireps.show', ['id' => $pirep->id]));
|
return redirect(route('frontend.pireps.show', ['id' => $pirep->id]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* Show the form for editing the specified Pirep.
|
||||||
|
* @param int $id
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function show($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
$pirep = $this->pirepRepo->find($id);
|
$pirep = $this->pirepRepo->findWithoutFail($id);
|
||||||
if (empty($pirep)) {
|
if (empty($pirep)) {
|
||||||
Flash::error('Pirep not found');
|
Flash::error('Pirep not found');
|
||||||
return redirect(route('frontend.pirep.index'));
|
return redirect(route('frontend.pireps.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$map_features = $this->geoSvc->pirepGeoJson($pirep);
|
$time = new Time($pirep->flight_time);
|
||||||
|
$pirep->hours = $time->hours;
|
||||||
|
$pirep->minutes = $time->minutes;
|
||||||
|
|
||||||
return $this->view('pireps.show', [
|
# Can we modify?
|
||||||
|
$read_only = $pirep->state !== PirepState::PENDING;
|
||||||
|
|
||||||
|
# set the custom fields
|
||||||
|
foreach($pirep->fields as $field) {
|
||||||
|
$pirep->{$field->slug} = $field->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
# set the fares
|
||||||
|
foreach($pirep->fares as $fare) {
|
||||||
|
$field_name = 'fare_'.$fare->fare_id;
|
||||||
|
$pirep->{$field_name} = $fare->count;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->view('pireps.edit', [
|
||||||
'pirep' => $pirep,
|
'pirep' => $pirep,
|
||||||
'map_features' => $map_features,
|
'read_only' => $read_only,
|
||||||
|
'aircraft' => $pirep->aircraft,
|
||||||
|
'aircraft_list' => $this->aircraftList(),
|
||||||
|
'airline_list' => $this->airlineRepo->selectBoxList(),
|
||||||
|
'airport_list' => $this->airportRepo->selectBoxList(),
|
||||||
|
'pirep_fields' => $this->pirepFieldRepo->all(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $id
|
||||||
|
* @param UpdatePirepRequest $request
|
||||||
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function update($id, UpdatePirepRequest $request)
|
||||||
|
{
|
||||||
|
$pirep = $this->pirepRepo->findWithoutFail($id);
|
||||||
|
|
||||||
|
if (empty($pirep)) {
|
||||||
|
Flash::error('Pirep not found');
|
||||||
|
return redirect(route('admin.pireps.index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$orig_route = $pirep->route;
|
||||||
|
|
||||||
|
$attrs = $request->all();
|
||||||
|
|
||||||
|
# Fix the time
|
||||||
|
$attrs['flight_time'] = Time::init(
|
||||||
|
$attrs['minutes'],
|
||||||
|
$attrs['hours'])->getMinutes();
|
||||||
|
|
||||||
|
$pirep = $this->pirepRepo->update($attrs, $id);
|
||||||
|
|
||||||
|
// A route change in the PIREP, so update the saved points in the ACARS table
|
||||||
|
if ($pirep->route !== $orig_route) {
|
||||||
|
$this->pirepSvc->saveRoute($pirep);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->saveCustomFields($pirep, $request);
|
||||||
|
$this->saveFares($pirep, $request);
|
||||||
|
|
||||||
|
Flash::success('Pirep updated successfully.');
|
||||||
|
return redirect(route('frontend.pireps.show', ['id' => $pirep->id]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,6 +283,11 @@ class Pirep extends BaseModel
|
|||||||
->orderBy('created_at', 'desc');
|
->orderBy('created_at', 'desc');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function fares()
|
||||||
|
{
|
||||||
|
return $this->hasMany(PirepFare::class, 'pirep_id');
|
||||||
|
}
|
||||||
|
|
||||||
public function fields()
|
public function fields()
|
||||||
{
|
{
|
||||||
return $this->hasMany(PirepFieldValues::class, 'pirep_id');
|
return $this->hasMany(PirepFieldValues::class, 'pirep_id');
|
||||||
|
41
app/Models/PirepFare.php
Normal file
41
app/Models/PirepFare.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PirepFare
|
||||||
|
* @package App\Models
|
||||||
|
*/
|
||||||
|
class PirepFare extends BaseModel
|
||||||
|
{
|
||||||
|
public $table = 'pirep_fares';
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
public $fillable = [
|
||||||
|
'pirep_id',
|
||||||
|
'fare_id',
|
||||||
|
'count',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'count' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
|
public static $rules = [
|
||||||
|
'count' => 'required',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relationships
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function fare()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Fare::class, 'fare_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function pirep()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Pirep::class, 'pirep_id');
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,8 @@ class FlightRepository extends BaseRepository implements CacheableInterface
|
|||||||
'arr_airport_id',
|
'arr_airport_id',
|
||||||
'dpt_airport_id',
|
'dpt_airport_id',
|
||||||
'flight_number' => 'like',
|
'flight_number' => 'like',
|
||||||
|
'flight_code' => 'like',
|
||||||
|
'flight_leg' => 'like',
|
||||||
'route' => 'like',
|
'route' => 'like',
|
||||||
'notes' => 'like',
|
'notes' => 'like',
|
||||||
];
|
];
|
||||||
@ -25,6 +27,33 @@ class FlightRepository extends BaseRepository implements CacheableInterface
|
|||||||
return Flight::class;
|
return Flight::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a flight based on the given criterea
|
||||||
|
* @param $airline_id
|
||||||
|
* @param $flight_num
|
||||||
|
* @param null $flight_code
|
||||||
|
* @param null $flight_leg
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function findFlight($airline_id, $flight_num, $flight_code=null, $flight_leg=null)
|
||||||
|
{
|
||||||
|
$where = [
|
||||||
|
'airline_id' => $airline_id,
|
||||||
|
'flight_num' => $flight_num,
|
||||||
|
'active' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
if(filled($flight_code)) {
|
||||||
|
$where['flight_code'] = $flight_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(filled('flight_leg')) {
|
||||||
|
$where['flight_leg'] = $flight_leg;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->findWhere($where);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the search criteria and return this with the stuff pushed
|
* Create the search criteria and return this with the stuff pushed
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
|
@ -37,8 +37,9 @@ Route::group([
|
|||||||
Route::match(['post', 'put'], 'settings', 'SettingsController@update')->name('settings.update');
|
Route::match(['post', 'put'], 'settings', 'SettingsController@update')->name('settings.update');
|
||||||
|
|
||||||
# pirep related routes
|
# pirep related routes
|
||||||
|
Route::get('pireps/fares', 'PirepController@fares');
|
||||||
|
Route::get('pireps/pending', 'PirepController@pending');
|
||||||
Route::resource('pireps', 'PirepController');
|
Route::resource('pireps', 'PirepController');
|
||||||
Route::match(['get'], 'pireps/pending', 'PirepController@pending');
|
|
||||||
Route::match(['get', 'post', 'delete'], 'pireps/{id}/comments', 'PirepController@comments');
|
Route::match(['get', 'post', 'delete'], 'pireps/{id}/comments', 'PirepController@comments');
|
||||||
Route::match(['post', 'put'], 'pireps/{id}/status', 'PirepController@status')->name('pirep.status');
|
Route::match(['post', 'put'], 'pireps/{id}/status', 'PirepController@status')->name('pirep.status');
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ Route::group([
|
|||||||
Route::get('flights/search', 'FlightController@search')->name('flights.search');
|
Route::get('flights/search', 'FlightController@search')->name('flights.search');
|
||||||
Route::resource('flights', 'FlightController');
|
Route::resource('flights', 'FlightController');
|
||||||
|
|
||||||
|
Route::get('pireps/fares', 'PirepController@fares');
|
||||||
Route::resource('pireps', 'PirepController');
|
Route::resource('pireps', 'PirepController');
|
||||||
|
|
||||||
Route::get('profile/regen_apikey', 'ProfileController@regen_apikey')
|
Route::get('profile/regen_apikey', 'ProfileController@regen_apikey')
|
||||||
|
@ -6,9 +6,50 @@ use App\Models\Fare;
|
|||||||
use App\Models\Flight;
|
use App\Models\Flight;
|
||||||
use App\Models\Subfleet;
|
use App\Models\Subfleet;
|
||||||
use App\Support\Math;
|
use App\Support\Math;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FareService
|
||||||
|
* @package App\Services
|
||||||
|
*/
|
||||||
class FareService extends BaseService
|
class FareService extends BaseService
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Get the fares for a particular flight, with an optional subfleet
|
||||||
|
* This will go through if there are any fares assigned to the flight,
|
||||||
|
* and then check the fares assigned on the subfleet, and give the
|
||||||
|
* final "authoritative" list of the fares for a flight.
|
||||||
|
*
|
||||||
|
* If a subfleet is passed in,
|
||||||
|
* @param Flight|null $flight
|
||||||
|
* @param Subfleet|null $subfleet
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getAllFares($flight, $subfleet)
|
||||||
|
{
|
||||||
|
if(!$flight) {
|
||||||
|
$flight_fares = collect();
|
||||||
|
} else {
|
||||||
|
$flight_fares = $this->getForFlight($flight);
|
||||||
|
}
|
||||||
|
|
||||||
|
$subfleet_fares = $this->getForSubfleet($subfleet);
|
||||||
|
|
||||||
|
# Go through all of the fares assigned by the subfleet
|
||||||
|
# See if any of the same fares are assigned to the flight
|
||||||
|
$fares = $subfleet_fares->map(function($fare, $idx) use ($flight_fares)
|
||||||
|
{
|
||||||
|
$flight_fare = $flight_fares->whereStrict('id', $fare->id)->first();
|
||||||
|
if(!$flight_fare) {
|
||||||
|
return $fare;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $flight_fare;
|
||||||
|
});
|
||||||
|
|
||||||
|
return $fares;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get fares
|
* Get fares
|
||||||
* @param $fare
|
* @param $fare
|
||||||
@ -70,7 +111,7 @@ class FareService extends BaseService
|
|||||||
* table to see if the price/cost/capacity has been overridden
|
* table to see if the price/cost/capacity has been overridden
|
||||||
* and return the correct amounts.
|
* and return the correct amounts.
|
||||||
* @param Flight $flight
|
* @param Flight $flight
|
||||||
* @return Fare[]
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getForFlight(Flight $flight)
|
public function getForFlight(Flight $flight)
|
||||||
{
|
{
|
||||||
@ -120,7 +161,7 @@ class FareService extends BaseService
|
|||||||
* table to see if the price/cost/capacity has been overridden
|
* table to see if the price/cost/capacity has been overridden
|
||||||
* and return the correct amounts.
|
* and return the correct amounts.
|
||||||
* @param Subfleet $subfleet
|
* @param Subfleet $subfleet
|
||||||
* @return Fare[]
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getForSubfleet(Subfleet $subfleet)
|
public function getForSubfleet(Subfleet $subfleet)
|
||||||
{
|
{
|
||||||
|
25
app/Services/FinanceService.php
Normal file
25
app/Services/FinanceService.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
class FinanceService extends BaseService
|
||||||
|
{
|
||||||
|
private $fareSvc,
|
||||||
|
$flightSvc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FinanceService constructor.
|
||||||
|
* @param FareService $fareSvc
|
||||||
|
* @param FlightService $flightSvc
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
FareService $fareSvc,
|
||||||
|
FlightService $flightSvc
|
||||||
|
) {
|
||||||
|
$this->fareSvc = $fareSvc;
|
||||||
|
$this->flightSvc = $flightSvc;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ namespace App\Services;
|
|||||||
|
|
||||||
use App\Exceptions\BidExists;
|
use App\Exceptions\BidExists;
|
||||||
use App\Models\Flight;
|
use App\Models\Flight;
|
||||||
|
use App\Models\Subfleet;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\UserBid;
|
use App\Models\UserBid;
|
||||||
use App\Repositories\FlightRepository;
|
use App\Repositories\FlightRepository;
|
||||||
@ -16,13 +17,19 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class FlightService extends BaseService
|
class FlightService extends BaseService
|
||||||
{
|
{
|
||||||
protected $flightRepo, $navDataRepo, $userSvc;
|
private $fareSvc,
|
||||||
|
$flightRepo,
|
||||||
|
$navDataRepo,
|
||||||
|
$userSvc;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
FareService $fareSvc,
|
||||||
FlightRepository $flightRepo,
|
FlightRepository $flightRepo,
|
||||||
NavdataRepository $navdataRepo,
|
NavdataRepository $navdataRepo,
|
||||||
UserService $userSvc
|
UserService $userSvc
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
|
$this->fareSvc = $fareSvc;
|
||||||
$this->flightRepo = $flightRepo;
|
$this->flightRepo = $flightRepo;
|
||||||
$this->navDataRepo = $navdataRepo;
|
$this->navDataRepo = $navdataRepo;
|
||||||
$this->userSvc = $userSvc;
|
$this->userSvc = $userSvc;
|
||||||
@ -41,7 +48,7 @@ class FlightService extends BaseService
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $this->flightRepo
|
return $this->flightRepo
|
||||||
->whereOrder($where, 'flight_number', 'asc');
|
->whereOrder($where, 'flight_number', 'asc');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,8 +77,8 @@ class FlightService extends BaseService
|
|||||||
/**
|
/**
|
||||||
* Only allow aircraft that are at the current departure airport
|
* Only allow aircraft that are at the current departure airport
|
||||||
*/
|
*/
|
||||||
if(setting('pireps.only_aircraft_at_dep_airport', false)) {
|
if (setting('pireps.only_aircraft_at_dep_airport', false)) {
|
||||||
foreach($subfleets as $subfleet) {
|
foreach ($subfleets as $subfleet) {
|
||||||
$subfleet->aircraft = $subfleet->aircraft->filter(
|
$subfleet->aircraft = $subfleet->aircraft->filter(
|
||||||
function ($aircraft, $i) use ($flight) {
|
function ($aircraft, $i) use ($flight) {
|
||||||
if ($aircraft->airport_id === $flight->dpt_airport_id) {
|
if ($aircraft->airport_id === $flight->dpt_airport_id) {
|
||||||
@ -106,11 +113,11 @@ class FlightService extends BaseService
|
|||||||
*/
|
*/
|
||||||
public function getRoute(Flight $flight)
|
public function getRoute(Flight $flight)
|
||||||
{
|
{
|
||||||
if(!$flight->route) {
|
if (!$flight->route) {
|
||||||
return collect();
|
return collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
$route_points = array_map(function($point) {
|
$route_points = array_map(function ($point) {
|
||||||
return strtoupper($point);
|
return strtoupper($point);
|
||||||
}, explode(' ', $flight->route));
|
}, explode(' ', $flight->route));
|
||||||
|
|
||||||
@ -118,7 +125,7 @@ class FlightService extends BaseService
|
|||||||
|
|
||||||
// Put it back into the original order the route is in
|
// Put it back into the original order the route is in
|
||||||
$return_points = [];
|
$return_points = [];
|
||||||
foreach($route_points as $rp) {
|
foreach ($route_points as $rp) {
|
||||||
$return_points[] = $route->where('id', $rp)->first();
|
$return_points[] = $route->where('id', $rp)->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,15 +142,15 @@ class FlightService extends BaseService
|
|||||||
public function addBid(Flight $flight, User $user)
|
public function addBid(Flight $flight, User $user)
|
||||||
{
|
{
|
||||||
# If it's already been bid on, then it can't be bid on again
|
# If it's already been bid on, then it can't be bid on again
|
||||||
if($flight->has_bid && setting('bids.disable_flight_on_bid')) {
|
if ($flight->has_bid && setting('bids.disable_flight_on_bid')) {
|
||||||
Log::info($flight->id . ' already has a bid, skipping');
|
Log::info($flight->id . ' already has a bid, skipping');
|
||||||
throw new BidExists();
|
throw new BidExists();
|
||||||
}
|
}
|
||||||
|
|
||||||
# See if we're allowed to have multiple bids or not
|
# See if we're allowed to have multiple bids or not
|
||||||
if(!setting('bids.allow_multiple_bids')) {
|
if (!setting('bids.allow_multiple_bids')) {
|
||||||
$user_bids = UserBid::where(['user_id' => $user->id])->first();
|
$user_bids = UserBid::where(['user_id' => $user->id])->first();
|
||||||
if($user_bids) {
|
if ($user_bids) {
|
||||||
Log::info('User "' . $user->id . '" already has bids, skipping');
|
Log::info('User "' . $user->id . '" already has bids, skipping');
|
||||||
throw new BidExists();
|
throw new BidExists();
|
||||||
}
|
}
|
||||||
@ -156,7 +163,7 @@ class FlightService extends BaseService
|
|||||||
];
|
];
|
||||||
|
|
||||||
$user_bid = UserBid::where($bid_data)->first();
|
$user_bid = UserBid::where($bid_data)->first();
|
||||||
if($user_bid) {
|
if ($user_bid) {
|
||||||
return $user_bid;
|
return $user_bid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,12 +186,12 @@ class FlightService extends BaseService
|
|||||||
'flight_id' => $flight->id, 'user_id' => $user->id
|
'flight_id' => $flight->id, 'user_id' => $user->id
|
||||||
])->first();
|
])->first();
|
||||||
|
|
||||||
if($user_bid) {
|
if ($user_bid) {
|
||||||
$user_bid->forceDelete();
|
$user_bid->forceDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
# Only flip the flag if there are no bids left for this flight
|
# Only flip the flag if there are no bids left for this flight
|
||||||
if(!UserBid::where('flight_id', $flight->id)->exists()) {
|
if (!UserBid::where('flight_id', $flight->id)->exists()) {
|
||||||
$flight->has_bid = false;
|
$flight->has_bid = false;
|
||||||
$flight->save();
|
$flight->save();
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ use App\Models\Enums\PirepSource;
|
|||||||
use App\Models\Enums\PirepState;
|
use App\Models\Enums\PirepState;
|
||||||
use App\Models\Navdata;
|
use App\Models\Navdata;
|
||||||
use App\Models\Pirep;
|
use App\Models\Pirep;
|
||||||
|
use App\Models\PirepFare;
|
||||||
use App\Models\PirepFieldValues;
|
use App\Models\PirepFieldValues;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Repositories\AcarsRepository;
|
use App\Repositories\AcarsRepository;
|
||||||
@ -210,6 +211,29 @@ class PIREPService extends BaseService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the list of fares
|
||||||
|
* @param $pirep_id
|
||||||
|
* @param array $fares ['field_id', 'count']
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function saveFares($pirep_id, array $fares)
|
||||||
|
{
|
||||||
|
if(!$fares) { return; }
|
||||||
|
|
||||||
|
# Remove all the previous fares
|
||||||
|
PirepFare::where('pirep_id', $pirep_id)->delete();
|
||||||
|
|
||||||
|
# Add them in
|
||||||
|
foreach($fares as $fare) {
|
||||||
|
$fare['pirep_id'] = $pirep_id;
|
||||||
|
# other fields: ['fare_id', 'count']
|
||||||
|
|
||||||
|
$field = new PirepFare($fare);
|
||||||
|
$field->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Pirep $pirep
|
* @param Pirep $pirep
|
||||||
* @param int $new_state
|
* @param int $new_state
|
||||||
|
@ -28,13 +28,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card border-blue-bottom">
|
|
||||||
<div class="content">
|
|
||||||
<h4>field values</h4>
|
|
||||||
@include('admin.pireps.field_values')
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card border-blue-bottom">
|
<div class="card border-blue-bottom">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h4>comments</h4>
|
<h4>comments</h4>
|
||||||
|
29
resources/views/admin/pireps/fares.blade.php
Normal file
29
resources/views/admin/pireps/fares.blade.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
@if($aircraft)
|
||||||
|
<table class="table table-hover table-responsive">
|
||||||
|
<thead>
|
||||||
|
<th></th>
|
||||||
|
<th>Count</th>
|
||||||
|
</thead>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($aircraft->subfleet->fares as $fare)
|
||||||
|
<tr>
|
||||||
|
<td>{!! $fare->name !!} ({!! $fare->code !!})</td>
|
||||||
|
<td>
|
||||||
|
<div class="form-group">
|
||||||
|
@if($read_only)
|
||||||
|
<p>{!! $pirep->{'fare_'.$fare->id} !!}</p>
|
||||||
|
{!! Form::hidden('fare_'.$fare->id) !!}
|
||||||
|
@else
|
||||||
|
{!! Form::number('fare_'.$fare->id, null, [
|
||||||
|
'class' => 'form-control',
|
||||||
|
'min' => 0,
|
||||||
|
'readonly' => $read_only]) !!}
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
@endif
|
@ -1,35 +1,30 @@
|
|||||||
<div id="pirep_field_values_wrapper">
|
<table class="table table-responsive table-hover" id="flight-fields-table">
|
||||||
<table class="table table-responsive" id="flight-fields-table">
|
|
||||||
<thead>
|
<thead>
|
||||||
<th>Name</th>
|
<th></th>
|
||||||
<th>Value</th>
|
<th>Value</th>
|
||||||
<th>Source</th>
|
<th>Source</th>
|
||||||
<th style="text-align: right;">Actions</th>
|
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach($pirep->fields as $field)
|
@foreach($pirep->fields as $field)
|
||||||
<tr>
|
<tr>
|
||||||
<td>{!! $field->name !!}</td>
|
|
||||||
<td>
|
<td>
|
||||||
<a class="inline" href="#" data-pk="{!! $field->id !!}" data-name="{!! $field->name !!}">{!! $field->value !!}</a>
|
{!! $field->name !!}
|
||||||
|
@if($field->required === true)
|
||||||
|
<span class="text-danger">*</span>
|
||||||
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td>{!! PirepSource::label($field->source) !!}</td>
|
<td>
|
||||||
<td style="width: 10%; text-align: right;" class="form-inline">
|
<div class="form-group">
|
||||||
{!! Form::open(['url' => '/admin/pireps/'.$pirep->id.'/fields',
|
{!! Form::text($field->slug, null, [
|
||||||
'method' => 'delete',
|
'class' => 'form-control'
|
||||||
'class' => 'pjax_form pirep_fields'
|
]) !!}
|
||||||
]) !!}
|
|
||||||
{!! Form::hidden('field_id', $field->id) !!}
|
|
||||||
<div class='btn-group'>
|
|
||||||
{{--{!! Form::button('<i class="fa fa-times"></i>',
|
|
||||||
['type' => 'submit',
|
|
||||||
'class' => 'btn btn-danger btn-xs'])
|
|
||||||
!!}--}}
|
|
||||||
</div>
|
</div>
|
||||||
{!! Form::close() !!}
|
<p class="text-danger">{{ $errors->first($field->slug) }}</p>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{!! PirepSource::label($field->source) !!}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
|
||||||
|
@ -1,23 +1,46 @@
|
|||||||
|
@if($read_only)
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
@component('admin.components.info')
|
||||||
|
Once a PIREP has been accepted/rejected, certain fields go into read-only mode.
|
||||||
|
@endcomponent
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-6">
|
||||||
{!! Form::label('flight_number', 'Flight Number/Route Code/Leg') !!}
|
{!! Form::label('flight_number', 'Flight Number/Route Code/Leg') !!}
|
||||||
<div class="row">
|
@if($read_only)
|
||||||
<div class="col-sm-4">
|
<p>{!! $pirep->ident !!}
|
||||||
{!! Form::text('flight_number', null, ['placeholder' => 'Flight Number', 'class' => 'form-control']) !!}
|
{!! Form::hidden('flight_number') !!}
|
||||||
<p class="text-danger">{{ $errors->first('flight_number') }}</p>
|
{!! Form::hidden('flight_code') !!}
|
||||||
|
{!! Form::hidden('flight_leg') !!}
|
||||||
|
</p>
|
||||||
|
@else
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-4">
|
||||||
|
{!! Form::text('flight_number', null, [
|
||||||
|
'placeholder' => 'Flight Number',
|
||||||
|
'class' => 'form-control']) !!}
|
||||||
|
<p class="text-danger">{{ $errors->first('flight_number') }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
{!! Form::text('route_code', null, [
|
||||||
|
'placeholder' => 'Code (optional)',
|
||||||
|
'class' => 'form-control']) !!}
|
||||||
|
<p class="text-danger">{{ $errors->first('route_code') }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
{!! Form::text('route_leg', null, [
|
||||||
|
'placeholder' => 'Leg (optional)',
|
||||||
|
'class' => 'form-control']) !!}
|
||||||
|
<p class="text-danger">{{ $errors->first('route_leg') }}</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-4">
|
@endif
|
||||||
{!! Form::text('route_code', null, ['placeholder' => 'Code (optional)', 'class' => 'form-control']) !!}
|
|
||||||
<p class="text-danger">{{ $errors->first('route_code') }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="col-sm-4">
|
|
||||||
{!! Form::text('route_leg', null, ['placeholder' => 'Leg (optional)', 'class' => 'form-control']) !!}
|
|
||||||
<p class="text-danger">{{ $errors->first('route_leg') }}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-6">
|
||||||
<p class="description">Filed Using:</span>
|
<p class="description">Filed Via:</p>
|
||||||
{!! PirepSource::label($pirep->source) !!}
|
{!! PirepSource::label($pirep->source) !!}
|
||||||
@if(filled($pirep->source_name))
|
@if(filled($pirep->source_name))
|
||||||
({!! $pirep->source_name !!})
|
({!! $pirep->source_name !!})
|
||||||
@ -27,44 +50,82 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-sm-3">
|
<div class="form-group col-sm-3">
|
||||||
{!! Form::label('airline_id', 'Airline') !!}
|
{!! Form::label('airline_id', 'Airline') !!}
|
||||||
<div class="row">
|
@if($read_only)
|
||||||
<div class="col-sm-12">
|
<p>{!! $pirep->airline->name !!}</p>
|
||||||
{!! Form::select('airline_id', $airlines, null, ['class' => 'form-control select2']) !!}
|
{!! Form::hidden('airline_id') !!}
|
||||||
<p class="text-danger">{{ $errors->first('airline_id') }}</p>
|
@else
|
||||||
</div>
|
{!! Form::select('airline_id', $airlines_list, null, [
|
||||||
</div>
|
'class' => 'form-control select2',
|
||||||
|
'readonly' => $read_only]) !!}
|
||||||
|
<p class="text-danger">{{ $errors->first('airline_id') }}</p>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-sm-3">
|
<div class="form-group col-sm-3">
|
||||||
{!! Form::label('aircraft_id', 'Aircraft:') !!}
|
{!! Form::label('aircraft_id', 'Aircraft:') !!}
|
||||||
{!! Form::select('aircraft_id', $aircraft, null, ['class' => 'form-control select2']) !!}
|
@if($read_only)
|
||||||
<p class="text-danger">{{ $errors->first('aircraft_id') }}</p>
|
<p>{!! $pirep->aircraft->name !!}</p>
|
||||||
|
{!! Form::hidden('aircraft_id') !!}
|
||||||
|
@else
|
||||||
|
{!! Form::select('aircraft_id', $aircraft_list, null, [
|
||||||
|
'id' => 'aircraft_select',
|
||||||
|
'class' => 'form-control select2',
|
||||||
|
'readonly' => $read_only
|
||||||
|
]) !!}
|
||||||
|
<p class="text-danger">{{ $errors->first('aircraft_id') }}</p>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-sm-3">
|
<div class="form-group col-sm-3">
|
||||||
{!! Form::label('dpt_airport_id', 'Departure Airport:') !!}
|
{!! Form::label('dpt_airport_id', 'Departure Airport:') !!}
|
||||||
{!! Form::select('dpt_airport_id', $airports, null, ['class' => 'form-control select2']) !!}
|
@if($read_only)
|
||||||
<p class="text-danger">{{ $errors->first('dpt_airport_id') }}</p>
|
<p>{!! $pirep->dpt_airport->id !!} - {!! $pirep->dpt_airport->name !!}</p>
|
||||||
|
{!! Form::hidden('dpt_airport_id') !!}
|
||||||
|
@else
|
||||||
|
{!! Form::select('dpt_airport_id', $airports_list, null, [
|
||||||
|
'class' => 'form-control select2',
|
||||||
|
'readonly' => $read_only]) !!}
|
||||||
|
<p class="text-danger">{{ $errors->first('dpt_airport_id') }}</p>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-sm-3">
|
<div class="form-group col-sm-3">
|
||||||
{!! Form::label('arr_airport_id', 'Arrival Airport:') !!}
|
{!! Form::label('arr_airport_id', 'Arrival Airport:') !!}
|
||||||
{!! Form::select('arr_airport_id', $airports, null, ['class' => 'form-control select2']) !!}
|
@if($read_only)
|
||||||
<p class="text-danger">{{ $errors->first('arr_airport_id') }}</p>
|
<p>{!! $pirep->arr_airport->id !!} - {!! $pirep->arr_airport->name !!}</p>
|
||||||
|
{!! Form::hidden('arr_airport_id') !!}
|
||||||
|
@else
|
||||||
|
{!! Form::select('arr_airport_id', $airports_list, null, ['class' => 'form-control select2']) !!}
|
||||||
|
<p class="text-danger">{{ $errors->first('arr_airport_id') }}</p>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<!-- Flight Time Field -->
|
<!-- Flight Time Field -->
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-6">
|
||||||
{!! Form::label('flight_time', 'Flight Time (hours & minutes):') !!}
|
{!! Form::label('flight_time', 'Flight Time (hours & minutes):') !!}
|
||||||
<div class="row">
|
@if($read_only)
|
||||||
<div class="col-sm-6">
|
<p>
|
||||||
{!! Form::number('hours', null, ['class' => 'form-control', 'placeholder' => 'hours', 'readonly' => $read_only]) !!}
|
{!! $pirep->hours !!} hours, {!! $pirep->minutes !!} minutes
|
||||||
|
{!! Form::hidden('hours') !!}
|
||||||
|
{!! Form::hidden('minutes') !!}
|
||||||
|
</p>
|
||||||
|
@else
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-6">
|
||||||
|
{!! Form::number('hours', null, [
|
||||||
|
'class' => 'form-control',
|
||||||
|
'placeholder' => 'hours',
|
||||||
|
'readonly' => $read_only]) !!}
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
{!! Form::number('minutes', null, [
|
||||||
|
'class' => 'form-control',
|
||||||
|
'placeholder' => 'minutes',
|
||||||
|
'readonly' => $read_only]) !!}
|
||||||
|
</div>
|
||||||
|
<p class="text-danger">{{ $errors->first('hours') }}</p>
|
||||||
|
<p class="text-danger">{{ $errors->first('minutes') }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6">
|
@endif
|
||||||
{!! Form::number('minutes', null, ['class' => 'form-control', 'placeholder' => 'minutes', 'readonly' => $read_only]) !!}
|
|
||||||
</div>
|
|
||||||
<p class="text-danger">{{ $errors->first('hours') }}</p>
|
|
||||||
<p class="text-danger">{{ $errors->first('minutes') }}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Level Field -->
|
<!-- Level Field -->
|
||||||
@ -72,7 +133,7 @@
|
|||||||
{!! Form::label('level', 'Flight Level:') !!}
|
{!! Form::label('level', 'Flight Level:') !!}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
{!! Form::text('level', null, ['class' => 'form-control']) !!}
|
{!! Form::number('level', null, ['class' => 'form-control', 'min' => 0]) !!}
|
||||||
<p class="text-danger">{{ $errors->first('level') }}</p>
|
<p class="text-danger">{{ $errors->first('level') }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -93,6 +154,34 @@
|
|||||||
<p class="text-danger">{{ $errors->first('notes') }}</p>
|
<p class="text-danger">{{ $errors->first('notes') }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{--
|
||||||
|
FARES
|
||||||
|
--}}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<hr>
|
||||||
|
<h3>fares</h3>
|
||||||
|
{{-- You don't want to change this ID unless you don't want the fares form to work :) --}}
|
||||||
|
<div id="fares_container">
|
||||||
|
@include('admin.pireps.fares')
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{--
|
||||||
|
CUSTOM FIELDS
|
||||||
|
--}}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<hr>
|
||||||
|
<h3>field values</h3>
|
||||||
|
{{-- You don't want to change this ID unless you don't want the fares form to work :) --}}
|
||||||
|
@include('admin.pireps.field_values')
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-sm-12">
|
<div class="form-group col-sm-12">
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
|
@ -17,6 +17,29 @@ const changeStatus = (values, fn) => {
|
|||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
const select_id = "select#aircraft_select";
|
||||||
|
const destContainer = $('#fares_container');
|
||||||
|
|
||||||
|
$(select_id).change((e) => {
|
||||||
|
const aircraft_id = $(select_id + " option:selected").val();
|
||||||
|
console.log('aircraft select change: ', aircraft_id);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "{!! url('/admin/pireps/fares') !!}?aircraft_id=" + aircraft_id,
|
||||||
|
type: 'GET',
|
||||||
|
headers: {
|
||||||
|
'x-api-key': '{!! Auth::user()->api_key !!}'
|
||||||
|
},
|
||||||
|
success: (data) => {
|
||||||
|
console.log('returned new fares', data);
|
||||||
|
destContainer.html(data);
|
||||||
|
},
|
||||||
|
error: () => {
|
||||||
|
destContainer.html('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
$(document).on('submit', 'form.pjax_form', function (event) {
|
$(document).on('submit', 'form.pjax_form', function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
$.pjax.submit(event, '#pirep_comments_wrapper', {push: false});
|
$.pjax.submit(event, '#pirep_comments_wrapper', {push: false});
|
||||||
|
10
resources/views/layouts/default/components/info.blade.php
Normal file
10
resources/views/layouts/default/components/info.blade.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<div>
|
||||||
|
<p style="float:left; margin-right: 10px; margin-left: 2px;">
|
||||||
|
<span style="font-size: 1.0em;">
|
||||||
|
<i class="fas fa-info-circle" style="color: #067ec1"></i>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
{{ $slot }}
|
||||||
|
</p>
|
||||||
|
</div>
|
@ -1,10 +1,10 @@
|
|||||||
@extends("layouts.${SKIN_NAME}.app")
|
@extends("layouts.${SKIN_NAME}.app")
|
||||||
@section('title', 'file pirep')
|
@section('title', 'File Flight Report')
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h2 class="description">new pilot report</h2>
|
<h2 class="description">New Flight Report</h2>
|
||||||
@include('flash::message')
|
@include('flash::message')
|
||||||
{!! Form::open(['route' => 'frontend.pireps.store']) !!}
|
{!! Form::open(['route' => 'frontend.pireps.store']) !!}
|
||||||
|
|
||||||
@ -15,10 +15,4 @@
|
|||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@section('scripts')
|
@include("layouts.${SKIN_NAME}.pireps.scripts")
|
||||||
<script>
|
|
||||||
$(document).ready(function() {
|
|
||||||
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
@endsection
|
|
||||||
|
16
resources/views/layouts/default/pireps/edit.blade.php
Normal file
16
resources/views/layouts/default/pireps/edit.blade.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
@extends("layouts.${SKIN_NAME}.app")
|
||||||
|
@section('title', 'Edit Flight Report')
|
||||||
|
@section('content')
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<h2 class="description">Edit Flight Report</h2>
|
||||||
|
@include('flash::message')
|
||||||
|
{!! Form::model($pirep, ['route' => ['frontend.pireps.update', $pirep->id], 'method' => 'patch']) !!}
|
||||||
|
|
||||||
|
@include("layouts.${SKIN_NAME}.pireps.fields")
|
||||||
|
|
||||||
|
{!! Form::close() !!}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
@include("layouts.${SKIN_NAME}.pireps.scripts")
|
27
resources/views/layouts/default/pireps/fares.blade.php
Normal file
27
resources/views/layouts/default/pireps/fares.blade.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
@if($aircraft)
|
||||||
|
<h3 class="description">Fares</h3>
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<th></th>
|
||||||
|
<th>Count</th>
|
||||||
|
</thead>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($aircraft->subfleet->fares as $fare)
|
||||||
|
<tr>
|
||||||
|
<td style="text-align: right;">{!! $fare->name !!} ({!! $fare->code !!})</td>
|
||||||
|
<td>
|
||||||
|
@if($read_only)
|
||||||
|
<p>{!! $pirep->{'fare_'.$fare->id} !!}</p>
|
||||||
|
{!! Form::hidden('fare_'.$fare->id) !!}
|
||||||
|
@else
|
||||||
|
<div class="input-group form-group">
|
||||||
|
{!! Form::number('fare_'.$fare->id, null, ['class' => 'form-control', 'min' => 0]) !!}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
@endif
|
@ -1,3 +1,22 @@
|
|||||||
|
{{--
|
||||||
|
|
||||||
|
NOTE ABOUT THIS VIEW
|
||||||
|
|
||||||
|
The fields that are marked "read-only", make sure the read-only status doesn't change!
|
||||||
|
If you make those fields editable, after they're in a read-only state, it can have
|
||||||
|
an impact on your stats and financials, and will require a recalculation of all the
|
||||||
|
flight reports that have been filed. You've been warned!
|
||||||
|
|
||||||
|
--}}
|
||||||
|
@if($read_only)
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
@component("layouts.${SKIN_NAME}.components.info")
|
||||||
|
Once a PIREP has been accepted/rejected, certain fields go into read-only mode.
|
||||||
|
@endcomponent
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<table class="table table-full-width">
|
<table class="table table-full-width">
|
||||||
@ -5,122 +24,202 @@
|
|||||||
|
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Airline</td>
|
<td>Airline</td>
|
||||||
<td>
|
<td>
|
||||||
|
@if($read_only)
|
||||||
|
<p>{!! $pirep->airline->name !!}</p>
|
||||||
|
{!! Form::hidden('airline_id') !!}
|
||||||
|
@else
|
||||||
<div class="input-group form-group">
|
<div class="input-group form-group">
|
||||||
{!! Form::select('airline_id', $airlines, null, ['class' => 'custom-select select2']) !!}
|
{!! Form::select('airline_id', $airline_list, null, [
|
||||||
|
'class' => 'custom-select select2',
|
||||||
|
'readonly' => $read_only]) !!}
|
||||||
</div>
|
</div>
|
||||||
<p class="text-danger">{{ $errors->first('airline_id') }}</p>
|
<p class="text-danger">{{ $errors->first('airline_id') }}</p>
|
||||||
</td>
|
@endif
|
||||||
</tr>
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Flight Number/Code/Leg</td>
|
<td>Flight Number/Code/Leg</td>
|
||||||
<td>
|
<td>
|
||||||
|
@if($read_only)
|
||||||
|
<p>{!! $pirep->ident !!}
|
||||||
|
{!! Form::hidden('flight_number') !!}
|
||||||
|
{!! Form::hidden('flight_code') !!}
|
||||||
|
{!! Form::hidden('flight_leg') !!}
|
||||||
|
</p>
|
||||||
|
@else
|
||||||
<div class="input-group form-group" style="max-width: 400px;">
|
<div class="input-group form-group" style="max-width: 400px;">
|
||||||
{!! Form::text('flight_number', null, ['placeholder' => 'Flight Number', 'class' => 'form-control']) !!}
|
{!! Form::text('flight_number', null, [
|
||||||
{!! Form::text('route_code', null, ['placeholder' => 'Code (optional)', 'class' => 'form-control']) !!}
|
'placeholder' => 'Flight Number',
|
||||||
{!! Form::text('route_leg', null, ['placeholder' => 'Leg (optional)', 'class' => 'form-control']) !!}
|
'class' => 'form-control',
|
||||||
|
'readonly' => $read_only]) !!}
|
||||||
|
|
||||||
|
{!! Form::text('route_code', null, [
|
||||||
|
'placeholder' => 'Code (optional)',
|
||||||
|
'class' => 'form-control',
|
||||||
|
'readonly' => $read_only]) !!}
|
||||||
|
|
||||||
|
{!! Form::text('route_leg', null, [
|
||||||
|
'placeholder' => 'Leg (optional)',
|
||||||
|
'class' => 'form-control',
|
||||||
|
'readonly' => $read_only]) !!}
|
||||||
</div>
|
</div>
|
||||||
<p class="text-danger">{{ $errors->first('flight_number') }}</p>
|
<p class="text-danger">{{ $errors->first('flight_number') }}</p>
|
||||||
<p class="text-danger">{{ $errors->first('route_code') }}</p>
|
<p class="text-danger">{{ $errors->first('route_code') }}</p>
|
||||||
<p class="text-danger">{{ $errors->first('route_leg') }}</p>
|
<p class="text-danger">{{ $errors->first('route_leg') }}</p>
|
||||||
</td>
|
@endif
|
||||||
</tr>
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Aircraft</td>
|
<td>Aircraft</td>
|
||||||
<td>
|
<td>
|
||||||
|
@if($read_only)
|
||||||
|
<p>{!! $pirep->aircraft->name !!}</p>
|
||||||
|
{!! Form::hidden('aircraft_id') !!}
|
||||||
|
@else
|
||||||
<div class="input-group form-group">
|
<div class="input-group form-group">
|
||||||
{!! Form::select('aircraft_id', $aircraft, null, ['class' => 'custom-select select2']) !!}
|
{{-- You probably don't want to change this ID if you want the fare select to work --}}
|
||||||
|
{!! Form::select('aircraft_id', $aircraft_list, null, [
|
||||||
|
'id' => 'aircraft_select',
|
||||||
|
'class' => 'custom-select select2',
|
||||||
|
'readonly' => $read_only
|
||||||
|
]) !!}
|
||||||
</div>
|
</div>
|
||||||
<p class="text-danger">{{ $errors->first('aircraft_id') }}</p>
|
<p class="text-danger">{{ $errors->first('aircraft_id') }}</p>
|
||||||
</td>
|
@endif
|
||||||
</tr>
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Origin Airport</td>
|
<td>Origin Airport</td>
|
||||||
<td>
|
<td>
|
||||||
|
@if($read_only)
|
||||||
|
<p>{!! $pirep->dpt_airport->id !!} - {!! $pirep->dpt_airport->name !!}</p>
|
||||||
|
{!! Form::hidden('dpt_airport_id') !!}
|
||||||
|
@else
|
||||||
<div class="input-group form-group">
|
<div class="input-group form-group">
|
||||||
{!! Form::select('dpt_airport_id', $airports, null, ['class' => 'custom-select select2']) !!}
|
{!! Form::select('dpt_airport_id', $airport_list, null, [
|
||||||
|
'class' => 'custom-select select2',
|
||||||
|
'readonly' => $read_only
|
||||||
|
]) !!}
|
||||||
</div>
|
</div>
|
||||||
<p class="text-danger">{{ $errors->first('dpt_airport_id') }}</p>
|
<p class="text-danger">{{ $errors->first('dpt_airport_id') }}</p>
|
||||||
</td>
|
@endif
|
||||||
</tr>
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Arrival Airport</td>
|
<td>Arrival Airport</td>
|
||||||
<td>
|
<td>
|
||||||
|
@if($read_only)
|
||||||
|
<p>{!! $pirep->arr_airport->id !!}
|
||||||
|
- {!! $pirep->arr_airport->name !!}</p>
|
||||||
|
{!! Form::hidden('arr_airport_id') !!}
|
||||||
|
@else
|
||||||
<div class="input-group form-group">
|
<div class="input-group form-group">
|
||||||
{!! Form::select('arr_airport_id', $airports, null, ['class' => 'custom-select select2']) !!}
|
{!! Form::select('arr_airport_id', $airport_list, null, [
|
||||||
|
'class' => 'custom-select select2',
|
||||||
|
'readonly' => $read_only
|
||||||
|
]) !!}
|
||||||
</div>
|
</div>
|
||||||
<p class="text-danger">{{ $errors->first('arr_airport_id') }}</p>
|
<p class="text-danger">{{ $errors->first('arr_airport_id') }}</p>
|
||||||
</td>
|
@endif
|
||||||
</tr>
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-text-top">Flight Time</td>
|
<td class="align-text-top">Flight Time</td>
|
||||||
<td>
|
<td>
|
||||||
|
@if($read_only)
|
||||||
|
<p>
|
||||||
|
{!! $pirep->hours !!} hours, {!! $pirep->minutes !!} minutes
|
||||||
|
{!! Form::hidden('hours') !!}
|
||||||
|
{!! Form::hidden('minutes') !!}
|
||||||
|
</p>
|
||||||
|
@else
|
||||||
<div class="input-group" style="max-width: 200px;">
|
<div class="input-group" style="max-width: 200px;">
|
||||||
{!! Form::number('hours', null, ['class' => 'form-control', 'placeholder' => 'hours']) !!}
|
{!! Form::number('hours', null, [
|
||||||
{!! Form::number('minutes', null, ['class' => 'form-control', 'placeholder' => 'minutes']) !!}
|
'class' => 'form-control',
|
||||||
|
'placeholder' => 'hours',
|
||||||
|
'min' => '0',
|
||||||
|
'readonly' => $read_only
|
||||||
|
]) !!}
|
||||||
|
|
||||||
|
{!! Form::number('minutes', null, [
|
||||||
|
'class' => 'form-control',
|
||||||
|
'placeholder' => 'minutes',
|
||||||
|
'min' => 0,
|
||||||
|
'readonly' => $read_only
|
||||||
|
]) !!}
|
||||||
</div>
|
</div>
|
||||||
<p class="text-danger">{{ $errors->first('hours') }}</p>
|
<p class="text-danger">{{ $errors->first('hours') }}</p>
|
||||||
<p class="text-danger">{{ $errors->first('minutes') }}</p>
|
<p class="text-danger">{{ $errors->first('minutes') }}</p>
|
||||||
</td>
|
@endif
|
||||||
</tr>
|
</td>
|
||||||
|
</tr>
|
||||||
{{--
|
|
||||||
Write out the custom fields, and label if they're required
|
|
||||||
--}}
|
|
||||||
@foreach($pirep_fields as $field)
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
{!! $field->name !!}
|
|
||||||
@if($field->required === true)
|
|
||||||
<span class="text-danger">*</span>
|
|
||||||
@endif
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<div class="input-group form-group">
|
|
||||||
{!! Form::text($field->slug, null, [
|
|
||||||
'class' => 'form-control'
|
|
||||||
]) !!}
|
|
||||||
</div>
|
|
||||||
<p class="text-danger">{{ $errors->first($field->slug) }}</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
@endforeach
|
|
||||||
|
|
||||||
|
{{--
|
||||||
|
Write out the custom fields, and label if they're required
|
||||||
|
--}}
|
||||||
|
@foreach($pirep_fields as $field)
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-text-top">Route</td>
|
<td>
|
||||||
|
{!! $field->name !!}
|
||||||
|
@if($field->required === true)
|
||||||
|
<span class="text-danger">*</span>
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="input-group form-group">
|
<div class="input-group form-group">
|
||||||
{!! Form::textarea('route', null, ['class' => 'form-control', 'placeholder' => 'Route']) !!}
|
{!! Form::text($field->slug, null, [
|
||||||
|
'class' => 'form-control'
|
||||||
|
]) !!}
|
||||||
</div>
|
</div>
|
||||||
<p class="text-danger">{{ $errors->first('route') }}</p>
|
<p class="text-danger">{{ $errors->first($field->slug) }}</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-text-top"><p class="">Notes</p></td>
|
<td class="align-text-top">Route</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="input-group form-group">
|
<div class="input-group form-group">
|
||||||
{!! Form::textarea('notes', null, ['class' => 'form-control', 'placeholder' => 'Notes']) !!}
|
{!! Form::textarea('route', null, ['class' => 'form-control', 'placeholder' => 'Route']) !!}
|
||||||
</div>
|
</div>
|
||||||
<p class="text-danger">{{ $errors->first('notes') }}</p>
|
<p class="text-danger">{{ $errors->first('route') }}</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td class="align-text-top"><p class="">Notes</p></td>
|
||||||
|
<td>
|
||||||
|
<div class="input-group form-group">
|
||||||
|
{!! Form::textarea('notes', null, ['class' => 'form-control', 'placeholder' => 'Notes']) !!}
|
||||||
|
</div>
|
||||||
|
<p class="text-danger">{{ $errors->first('notes') }}</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
{{-- You don't want to change this ID unless you don't want the fares form to work :) --}}
|
||||||
|
<div id="fares_container" class="col-sm-12">
|
||||||
|
@include("layouts.${SKIN_NAME}.pireps.fares")
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{!! Form::submit('Submit PIREP', ['class' => 'btn btn-primary']) !!}
|
{!! Form::submit('Save PIREP', ['class' => 'btn btn-primary']) !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
@section('scripts')
|
|
||||||
<script>
|
|
||||||
function changeStatus(values) {
|
|
||||||
var destContainer = '#pirep_' + values.pirep_id + '_container';
|
|
||||||
$.ajax({
|
|
||||||
url: '/admin/pireps/' + values.pirep_id + '/status',
|
|
||||||
data: values,
|
|
||||||
type: 'POST',
|
|
||||||
success: function (data) {
|
|
||||||
// console.log(data);
|
|
||||||
$(destContainer).replaceWith(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//$(document).ready(function() {
|
|
||||||
$(document).on('submit', 'form.pirep_submit_status', function (event) {
|
|
||||||
console.log(event);
|
|
||||||
|
|
||||||
event.preventDefault();
|
|
||||||
var values = {
|
|
||||||
pirep_id: $(this).attr('pirep_id'),
|
|
||||||
new_status: $(this).attr('new_status')
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log(values);
|
|
||||||
console.log('Changing PIREP ' + values.pirep_id + ' to state ' + values.new_status);
|
|
||||||
|
|
||||||
//var destContainer = '#pirep_' + pirep_id + '_container';
|
|
||||||
//$.pjax.submit(event, destContainer, { push: false, maxCacheLength: 0 });
|
|
||||||
|
|
||||||
changeStatus(values);
|
|
||||||
});
|
|
||||||
//});
|
|
||||||
</script>
|
|
||||||
@endsection
|
|
28
resources/views/layouts/default/pireps/scripts.blade.php
Normal file
28
resources/views/layouts/default/pireps/scripts.blade.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
@section('scripts')
|
||||||
|
<script>
|
||||||
|
$(document).ready(() => {
|
||||||
|
const select_id = "select#aircraft_select";
|
||||||
|
const destContainer = $('#fares_container');
|
||||||
|
|
||||||
|
$(select_id).change((e) => {
|
||||||
|
const aircraft_id = $(select_id + " option:selected").val();
|
||||||
|
console.log('aircraft select change: ', aircraft_id);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "{!! url('/pireps/fares') !!}?aircraft_id=" + aircraft_id,
|
||||||
|
type: 'GET',
|
||||||
|
headers: {
|
||||||
|
'x-api-key': '{!! Auth::user()->api_key !!}'
|
||||||
|
},
|
||||||
|
success: (data) => {
|
||||||
|
console.log('returned new fares', data);
|
||||||
|
destContainer.html(data);
|
||||||
|
},
|
||||||
|
error: () => {
|
||||||
|
destContainer.html('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endsection
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<table class="table">
|
<table class="table table-hover">
|
||||||
<tr>
|
<tr>
|
||||||
<td>Status</td>
|
<td>Status</td>
|
||||||
<td>
|
<td>
|
||||||
@ -23,6 +23,7 @@
|
|||||||
@else
|
@else
|
||||||
<div class="badge badge-info">
|
<div class="badge badge-info">
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
{!! PirepState::label($pirep->state) !!}</div>
|
{!! PirepState::label($pirep->state) !!}</div>
|
||||||
|
|
||||||
<span class="description" style="padding-left: 20px;">
|
<span class="description" style="padding-left: 20px;">
|
||||||
@ -71,11 +72,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{--
|
||||||
|
Show the fields that have been entered
|
||||||
|
--}}
|
||||||
|
|
||||||
@if(count($pirep->fields) > 0)
|
@if(count($pirep->fields) > 0)
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h3 class="description">fields</h3>
|
<h3 class="description">fields</h3>
|
||||||
<table class="table">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Value</th>
|
<th>Value</th>
|
||||||
@ -93,6 +98,32 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
{{--
|
||||||
|
Show the fares that have been entered
|
||||||
|
--}}
|
||||||
|
|
||||||
|
@if(count($pirep->fares) > 0)
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<h3 class="description">fares</h3>
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<th>Class</th>
|
||||||
|
<th>Count</th>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($pirep->fares as $fare)
|
||||||
|
<tr>
|
||||||
|
<td>{!! $fare->fare->name !!} ({!! $fare->fare->code !!})</td>
|
||||||
|
<td>{!! $fare->count !!}</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
@include("layouts.${SKIN_NAME}.pireps.map")
|
@include("layouts.${SKIN_NAME}.pireps.map")
|
||||||
|
|
||||||
@if(count($pirep->acars_logs) > 0)
|
@if(count($pirep->acars_logs) > 0)
|
||||||
|
@ -171,4 +171,103 @@ class FinanceTest extends TestCase
|
|||||||
$this->assertEquals($new_cost, $ac_fares[0]->cost);
|
$this->assertEquals($new_cost, $ac_fares[0]->cost);
|
||||||
$this->assertEquals($new_capacity, $ac_fares[0]->capacity);
|
$this->assertEquals($new_capacity, $ac_fares[0]->capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test getting the fares from the flight svc. Have a few base fares
|
||||||
|
* and then override some of them
|
||||||
|
*/
|
||||||
|
public function testGetFaresWithOverrides()
|
||||||
|
{
|
||||||
|
$flight = factory(App\Models\Flight::class)->create();
|
||||||
|
$subfleet = factory(App\Models\Subfleet::class)->create();
|
||||||
|
[$fare1, $fare2, $fare3, $fare4] = factory(App\Models\Fare::class, 4)->create();
|
||||||
|
|
||||||
|
# add to the subfleet, and just override one of them
|
||||||
|
$this->fareSvc->setForSubfleet($subfleet, $fare1);
|
||||||
|
$this->fareSvc->setForSubfleet($subfleet, $fare2, [
|
||||||
|
'price' => 100,
|
||||||
|
'cost' => 50,
|
||||||
|
'capacity' => 25,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->fareSvc->setForSubfleet($subfleet, $fare3);
|
||||||
|
|
||||||
|
# Now set the last one to the flight and then override stuff
|
||||||
|
$this->fareSvc->setForFlight($flight, $fare3, [
|
||||||
|
'price' => '300%',
|
||||||
|
'cost' => 250,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$fare3_price = Math::addPercent($fare3->price, 300);
|
||||||
|
|
||||||
|
# Assign another one to the flight, that's not on the subfleet
|
||||||
|
# This one should NOT be returned in the list of fares
|
||||||
|
$this->fareSvc->setForFlight($flight, $fare4);
|
||||||
|
|
||||||
|
$fares = $this->fareSvc->getAllFares($flight, $subfleet);
|
||||||
|
$this->assertCount(3, $fares);
|
||||||
|
|
||||||
|
foreach($fares as $fare) {
|
||||||
|
switch($fare->id) {
|
||||||
|
case $fare1->id:
|
||||||
|
$this->assertEquals($fare->price, $fare1->price);
|
||||||
|
$this->assertEquals($fare->cost, $fare1->cost);
|
||||||
|
$this->assertEquals($fare->capacity, $fare1->capacity);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case $fare2->id:
|
||||||
|
$this->assertEquals($fare->price, 100);
|
||||||
|
$this->assertEquals($fare->cost, 50);
|
||||||
|
$this->assertEquals($fare->capacity, 25);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case $fare3->id:
|
||||||
|
$this->assertEquals($fare->price, $fare3_price);
|
||||||
|
$this->assertEquals($fare->cost, 250);
|
||||||
|
$this->assertEquals($fare->capacity, $fare3->capacity);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetFaresNoFlightOverrides()
|
||||||
|
{
|
||||||
|
$subfleet = factory(App\Models\Subfleet::class)->create();
|
||||||
|
[$fare1, $fare2, $fare3] = factory(App\Models\Fare::class, 3)->create();
|
||||||
|
|
||||||
|
# add to the subfleet, and just override one of them
|
||||||
|
$this->fareSvc->setForSubfleet($subfleet, $fare1);
|
||||||
|
$this->fareSvc->setForSubfleet($subfleet, $fare2, [
|
||||||
|
'price' => 100,
|
||||||
|
'cost' => 50,
|
||||||
|
'capacity' => 25,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->fareSvc->setForSubfleet($subfleet, $fare3);
|
||||||
|
|
||||||
|
$fares = $this->fareSvc->getAllFares(null, $subfleet);
|
||||||
|
$this->assertCount(3, $fares);
|
||||||
|
|
||||||
|
foreach ($fares as $fare) {
|
||||||
|
switch ($fare->id) {
|
||||||
|
case $fare1->id:
|
||||||
|
$this->assertEquals($fare->price, $fare1->price);
|
||||||
|
$this->assertEquals($fare->cost, $fare1->cost);
|
||||||
|
$this->assertEquals($fare->capacity, $fare1->capacity);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case $fare2->id:
|
||||||
|
$this->assertEquals($fare->price, 100);
|
||||||
|
$this->assertEquals($fare->cost, 50);
|
||||||
|
$this->assertEquals($fare->capacity, 25);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case $fare3->id:
|
||||||
|
$this->assertEquals($fare->price, $fare3->price);
|
||||||
|
$this->assertEquals($fare->cost, $fare3->cost);
|
||||||
|
$this->assertEquals($fare->capacity, $fare3->capacity);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user