Add fares and set prices on flights #125

This commit is contained in:
Nabeel Shahzad
2018-01-07 10:38:16 -06:00
parent 7e45291b27
commit 0495ff27cb
15 changed files with 285 additions and 102 deletions

View File

@@ -30,9 +30,10 @@ class CreateSettingsTable extends Migration
$this->addCounterGroups([
'general' => 1,
'flights' => 20,
'bids' => 40,
'pireps' => 60,
'pilots' => 80,
'finances' => 40,
'bids' => 60,
'pireps' => 80,
'pilots' => 100,
]);
/**
@@ -140,6 +141,15 @@ class CreateSettingsTable extends Migration
'type' => 'boolean',
'description' => 'Whether or not someone can bid on multiple flights',
],
/**
* FINANCES
*/
/**
* PIREPS
*/
[
'id' => $this->formatSettingId('pireps.duplicate_check_time'),
'order' => $this->getNextOrderNumber('pireps'),
@@ -160,6 +170,11 @@ class CreateSettingsTable extends Migration
'type' => 'boolean',
'description' => 'Hide any cancelled PIREPs in the front-end',
],
/**
* PILOTS
*/
[
'id' => $this->formatSettingId('pilots.id_length'),
'order' => $this->getNextOrderNumber('pilots'),

View File

@@ -2,14 +2,19 @@
namespace App\Http\Controllers\Admin;
use App\Models\Flight;
use App\Models\FlightFields;
use App\Http\Requests\CreateFlightRequest;
use App\Http\Requests\UpdateFlightRequest;
use App\Repositories\AirlineRepository;
use App\Repositories\AirportRepository;
use App\Repositories\FareRepository;
use App\Repositories\FlightRepository;
use App\Repositories\SubfleetRepository;
use App\Services\FareService;
use App\Services\FlightService;
use Illuminate\Http\Request;
use Flash;
use Response;
@@ -18,20 +23,26 @@ class FlightController extends BaseController
{
private $airlineRepo,
$airportRepo,
$fareRepo,
$flightRepo,
$fareSvc,
$flightSvc,
$subfleetRepo;
public function __construct(
AirlineRepository $airlineRepo,
AirportRepository $airportRepo,
FareRepository $fareRepo,
FlightRepository $flightRepo,
FareService $fareSvc,
FlightService $flightSvc,
SubfleetRepository $subfleetRepo
) {
$this->airlineRepo = $airlineRepo;
$this->airportRepo = $airportRepo;
$this->fareRepo = $fareRepo;
$this->flightRepo = $flightRepo;
$this->fareSvc = $fareSvc;
$this->flightSvc = $flightSvc;
$this->subfleetRepo = $subfleetRepo;
}
@@ -135,6 +146,7 @@ class FlightController extends BaseController
'flight' => $flight,
'airlines' => $this->airlineRepo->selectBoxList(),
'airports' => $this->airportRepo->selectBoxList(),
'avail_fares' => $this->getAvailFares($flight),
'avail_subfleets' => $avail_subfleets,
]);
}
@@ -270,4 +282,71 @@ class FlightController extends BaseController
return $this->return_subfleet_view($flight);
}
/**
* Get all the fares that haven't been assigned to a given subfleet
*/
protected function getAvailFares($flight)
{
$retval = [];
$all_fares = $this->fareRepo->all();
$avail_fares = $all_fares->except($flight->fares->modelKeys());
foreach ($avail_fares as $fare) {
$retval[$fare->id] = $fare->name .
' (base price: '.$fare->price.')';
}
return $retval;
}
/**
* @param Flight $flight
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
protected function return_fares_view(Flight $flight)
{
$flight->refresh();
return view('admin.flights.fares', [
'flight' => $flight,
'avail_fares' => $this->getAvailFares($flight),
]);
}
/**
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function fares(Request $request)
{
$id = $request->id;
$flight = $this->flightRepo->findWithoutFail($id);
if (empty($flight)) {
return $this->return_fares_view($flight);
}
if ($request->isMethod('get')) {
return $this->return_fares_view($flight);
}
/**
* update specific fare data
*/
if ($request->isMethod('post')) {
$fare = $this->fareRepo->findWithoutFail($request->fare_id);
$this->fareSvc->setForFlight($flight, $fare);
} // update the pivot table with overrides for the fares
elseif ($request->isMethod('put')) {
$override = [];
$fare = $this->fareRepo->findWithoutFail($request->fare_id);
$override[$request->name] = $request->value;
$this->fareSvc->setForFlight($flight, $fare, $override);
} // dissassociate fare from teh aircraft
elseif ($request->isMethod('delete')) {
$fare = $this->fareRepo->findWithoutFail($request->fare_id);
$this->fareSvc->delFareFromFlight($flight, $fare);
}
return $this->return_fares_view($flight);
}
}

View File

@@ -11,15 +11,19 @@ use App\Models\Enums\FuelType;
use App\Models\Airline;
use App\Models\Subfleet;
use App\Http\Requests\CreateSubfleetRequest;
use App\Http\Requests\UpdateSubfleetRequest;
use App\Repositories\FareRepository;
use App\Repositories\SubfleetRepository;
use App\Services\FareService;
class SubfleetController extends BaseController
{
/** @var SubfleetRepository */
private $subfleetRepo, $fareRepo;
private $subfleetRepo, $fareRepo, $fareSvc;
/**
* SubfleetController constructor.
@@ -29,10 +33,12 @@ class SubfleetController extends BaseController
*/
public function __construct(
SubfleetRepository $subfleetRepo,
FareRepository $fareRepo
FareRepository $fareRepo,
FareService $fareSvc
) {
$this->subfleetRepo = $subfleetRepo;
$this->fareRepo = $fareRepo;
$this->fareSvc = $fareSvc;
}
/**
@@ -84,10 +90,9 @@ class SubfleetController extends BaseController
/**
* Store a newly created Subfleet in storage.
*
* @param CreateSubfleetRequest $request
*
* @return Response
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function store(CreateSubfleetRequest $request)
{
@@ -100,9 +105,7 @@ class SubfleetController extends BaseController
/**
* Display the specified Subfleet.
*
* @param int $id
*
* @return Response
*/
public function show($id)
@@ -123,9 +126,7 @@ class SubfleetController extends BaseController
/**
* Show the form for editing the specified Subfleet.
*
* @param int $id
*
* @return Response
*/
public function edit($id)
@@ -148,11 +149,10 @@ class SubfleetController extends BaseController
/**
* Update the specified Subfleet in storage.
*
* @param int $id
* @param int $id
* @param UpdateSubfleetRequest $request
*
* @return Response
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function update($id, UpdateSubfleetRequest $request)
{
@@ -163,7 +163,7 @@ class SubfleetController extends BaseController
return redirect(route('admin.subfleets.index'));
}
$subfleet = $this->subfleetRepo->update($request->all(), $id);
$this->subfleetRepo->update($request->all(), $id);
Flash::success('Subfleet updated successfully.');
return redirect(route('admin.subfleets.index'));
@@ -171,9 +171,7 @@ class SubfleetController extends BaseController
/**
* Remove the specified Subfleet from storage.
*
* @param int $id
*
* @return Response
*/
public function destroy($id)
@@ -191,6 +189,10 @@ class SubfleetController extends BaseController
return redirect(route('admin.subfleets.index'));
}
/**
* @param Subfleet $subfleet
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
protected function return_fares_view(Subfleet $subfleet)
{
$subfleet->refresh();
@@ -204,7 +206,6 @@ class SubfleetController extends BaseController
/**
* @param Request $request
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function fares(Request $request)
@@ -217,8 +218,6 @@ class SubfleetController extends BaseController
//return view('admin.aircraft.fares', ['fares' => []]);
}
$fare_svc = app('App\Services\FareService');
if ($request->isMethod('get')) {
return $this->return_fares_view($subfleet);
}
@@ -228,7 +227,7 @@ class SubfleetController extends BaseController
*/
if ($request->isMethod('post')) {
$fare = $this->fareRepo->findWithoutFail($request->fare_id);
$fare_svc->setForSubfleet($subfleet, $fare);
$this->fareSvc->setForSubfleet($subfleet, $fare);
}
// update the pivot table with overrides for the fares
@@ -236,13 +235,13 @@ class SubfleetController extends BaseController
$override = [];
$fare = $this->fareRepo->findWithoutFail($request->fare_id);
$override[$request->name] = $request->value;
$fare_svc->setForSubfleet($subfleet, $fare, $override);
$this->fareSvc->setForSubfleet($subfleet, $fare, $override);
}
// dissassociate fare from teh aircraft
elseif ($request->isMethod('delete')) {
$fare = $this->fareRepo->findWithoutFail($request->fare_id);
$fare_svc->delFareFromSubfleet($subfleet, $fare);
$this->fareSvc->delFareFromSubfleet($subfleet, $fare);
}
return $this->return_fares_view($subfleet);

View File

@@ -23,6 +23,7 @@ Route::group([
# flights and aircraft associations
Route::resource('flights', 'FlightController');
Route::match(['get', 'post', 'put', 'delete'], 'flights/{id}/fares', 'FlightController@fares');
Route::match(['get', 'post', 'put', 'delete'], 'flights/{id}/fields', 'FlightController@fields');
Route::match(['get', 'post', 'put', 'delete'], 'flights/{id}/subfleets', 'FlightController@subfleets');

View File

@@ -14,7 +14,6 @@
"axios": "^0.17",
"bootstrap-sass": "^3.3.7",
"bootstrap3": "^3.3.5",
"marked": "0.3.9",
"cross-env": "^5.1.3",
"eonasdan-bootstrap-datetimepicker": "^4.17.47",
"icheck": "^1.0.2",
@@ -25,6 +24,7 @@
"leaflet-ajax": "2.1.0",
"leaflet-rotatedmarker": "^0.2.0",
"lodash": "4.17.4",
"marked": "0.3.9",
"moment": "^2.20.1",
"pjax": "^0.2.4",
"popper.js": "^1.13.0",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -40,7 +40,7 @@
padding: 15px 15px 10px 15px;
}
.header{
padding: 20px 20px 0;
padding: 0px 0px 10px 0;
}
.description{
font-size: $font-paragraph;

View File

@@ -1,12 +1,12 @@
{
"/assets/admin/vendor/paper-dashboard.css": "/assets/admin/vendor/paper-dashboard.css?id=233e12aabc29a3c6fba3",
"/assets/admin/vendor/paper-dashboard.css": "/assets/admin/vendor/paper-dashboard.css?id=c179175d87a4cef3a3f1",
"/assets/frontend/css/now-ui-kit.css": "/assets/frontend/css/now-ui-kit.css?id=58ec3dc768f07fee143a",
"/assets/system/js/jquery.js": "/assets/system/js/jquery.js?id=09dd64a64ba840c31a81",
"/assets/fonts/glyphicons-halflings-regular.woff2": "/assets/fonts/glyphicons-halflings-regular.woff2?id=b5b5055c6d812c0f9f0d",
"/assets/admin/fonts/glyphicons-halflings-regular.woff2": "/assets/admin/fonts/glyphicons-halflings-regular.woff2?id=b5b5055c6d812c0f9f0d",
"/assets/admin/css/clear.png": "/assets/admin/css/clear.png?id=0e92f4c3efc6988a3c96",
"/assets/admin/css/loading.gif": "/assets/admin/css/loading.gif?id=90a4b76b4f11558691f6",
"/assets/admin/css/vendor.min.css": "/assets/admin/css/vendor.min.css?id=dd0f6c4b8953c784240e",
"/assets/admin/css/vendor.min.css": "/assets/admin/css/vendor.min.css?id=09dd40e12d15cdfce5b9",
"/assets/admin/js/vendor.js": "/assets/admin/js/vendor.js?id=0f6b516f7ea80d70d407",
"/assets/admin/css/blue.png": "/assets/admin/css/blue.png?id=753a3c0dec86d3a38d9c",
"/assets/admin/css/blue@2x.png": "/assets/admin/css/blue@2x.png?id=97da23d47b838cbd4bef",

View File

@@ -22,5 +22,11 @@
@include('admin.flights.subfleets')
</div>
</div>
<div class="card border-blue-bottom">
<div class="content">
@include('admin.flights.fares')
</div>
</div>
@endsection
@include('admin.flights.scripts')

View File

@@ -0,0 +1,78 @@
<div id="flight_fares_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
<div class="header">
<h3>fares</h3>
<p class="category">
<i class="icon fa fa-info">&nbsp;&nbsp;</i>
Fares assigned to the current flight. These can be overridden,
otherwise, the values used come from the subfleet of the aircraft
that the flight is filed with. Only assign the fares you want to
override.
</p>
</div>
<table id="flight_fares"
class="table table-hover"
role="grid" aria-describedby="aircraft_fares_info">
<thead>
<tr role="row">
<th>name</th>
<th style="text-align: center;">code</th>
<th>capacity</th>
<th>price</th>
<th>cost</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach($flight->fares as $atf)
<tr>
<td class="sorting_1">{!! $atf->name !!}</td>
<td style="text-align: center;">{!! $atf->code !!}</td>
<td>
<a href="#" data-pk="{!! $atf->id !!}" data-name="capacity">{!! $atf->pivot->capacity !!}</a>
</td>
<td>
<a href="#" data-pk="{!! $atf->id !!}" data-name="price">{!! $atf->pivot->price !!}</a>
</td>
<td>
<a href="#" data-pk="{!! $atf->id !!}" data-name="cost">{!! $atf->pivot->cost !!}</a>
</td>
<td style="text-align: right; width:3%;">
{!! Form::open(['url' => '/admin/flights/'.$flight->id.'/fares',
'method' => 'delete',
'class' => 'pjax_fares_form'
])
!!}
{!! Form::hidden('fare_id', $atf->id) !!}
{!! Form::button('<i class="fa fa-times"></i>',
['type' => 'submit',
'class' => 'btn btn-sm btn-danger btn-icon']) !!}
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
<hr />
<div class="row">
<div class="col-xs-12">
<div class="text-right">
{!! Form::open(['url' => '/admin/flights/'.$flight->id.'/fares',
'method' => 'post',
'class' => 'pjax_fares_form form-inline'
])
!!}
{!! Form::select('fare_id', $avail_fares, null, [
'placeholder' => 'Select Fare',
'class' => 'ac-fare-dropdown form-control input-lg select2',
])
!!}
{!! Form::button('<i class="glyphicon glyphicon-plus"></i> add',
['type' => 'submit',
'class' => 'btn btn-success btn-s']) !!}
{!! Form::close() !!}
</div>
</div>
</div>
</div>

View File

@@ -24,4 +24,3 @@
</div>
</div>
@endsection
@include('admin.flights.scripts')

View File

@@ -1,35 +1,64 @@
@section('scripts')
<script>
$(document).ready(function () {
$('#flight_fields_wrapper a.inline').editable({
type: 'text',
mode: 'inline',
emptytext: '0',
url: '/admin/flights/{!! $flight->id !!}/fields',
ajaxOptions: {'type': 'put'},
params: function (params) {
return {
field_id: params.pk,
name: params.name,
value: params.value
}
function setEditable() {
$('#flight_fares a').editable({
type: 'text',
mode: 'inline',
emptytext: 'inherited',
url: '{!! url('/admin/flights/'.$flight->id.'/fares') !!}',
title: 'Enter override value',
ajaxOptions: {'type': 'put'},
params: function (params) {
return {
fare_id: params.pk,
name: params.name,
value: params.value
}
});
$(document).on('submit', 'form.pjax_flight_fields', function (event) {
event.preventDefault();
$.pjax.submit(event, '#flight_fields_wrapper', {push: false});
});
$(document).on('submit', 'form.pjax_subfleet_form', function (event) {
event.preventDefault();
$.pjax.submit(event, '#subfleet_flight_wrapper', {push: false});
});
$(document).on('pjax:complete', function () {
$(".select2").select2();
});
}
});
}
$(document).ready(function () {
setEditable();
$('#flight_fields_wrapper a.inline').editable({
type: 'text',
mode: 'inline',
emptytext: '0',
url: '/admin/flights/{!! $flight->id !!}/fields',
ajaxOptions: {'type': 'put'},
params: function (params) {
return {
field_id: params.pk,
name: params.name,
value: params.value
}
}
});
$(document).on('submit', 'form.pjax_flight_fields', function (event) {
event.preventDefault();
$.pjax.submit(event, '#flight_fields_wrapper', {push: false});
});
$(document).on('submit', 'form.pjax_subfleet_form', function (event) {
event.preventDefault();
$.pjax.submit(event, '#subfleet_flight_wrapper', {push: false});
});
$(document).on('submit', 'form.pjax_fares_form', function (event) {
event.preventDefault();
console.log(event);
$.pjax.submit(event, '#flight_fares_wrapper', {push: false});
setEditable();
});
$(document).on('pjax:complete', function () {
$(".select2").select2();
setEditable();
});
});
</script>
@endsection

View File

@@ -10,21 +10,10 @@
{!! Form::close() !!}
</div>
</div>
<div class="card border-blue-bottom">
<div class="header">
<h3>fares</h3>
<p class="category">
<i class="icon fa fa-info">&nbsp;&nbsp;</i>
Fares assigned to the current subfleet. These can be overridden,
otherwise, the value used is the default, which comes from the fare.
</p>
</div>
<div class="content">
<div class="row">
<div class="col-xs-12">
@include('admin.subfleets.fares')
</div>
</div>
@include('admin.subfleets.fares')
</div>
</div>
@endsection

View File

@@ -1,42 +1,30 @@
{{--<div class="row"> <div class="col-12">--}}
<div id="aircraft_fares_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
<div class="header">
<h3>fares</h3>
<p class="category">
<i class="icon fa fa-info">&nbsp;&nbsp;</i>
Fares assigned to the current subfleet. These can be overridden,
otherwise, the value used is the default, which comes from the fare.
</p>
</div>
<br />
<table id="aircraft_fares"
class="table table-bordered table-hover dataTable"
role="grid" aria-describedby="aircraft_fares_info">
<thead>
<tr role="row">
<th class="sorting" tabindex="0" aria-controls="aircraft_fares"
rowspan="1" colspan="1"
aria-label="name: activate to sort column ascending">
name
</th>
<th class="sorting_asc" tabindex="0" style="text-align: center;"
aria-controls="aircraft_fares" rowspan="1" colspan="1"
aria-sort="ascending"
aria-label="code: activate to sort column descending">
code
</th>
<th class="sorting" tabindex="0" aria-controls="aircraft_fares"
rowspan="1" colspan="1"
aria-label="capacity: activate to sort column ascending">
capacity (default)
</th>
<th class="sorting" tabindex="0" aria-controls="aircraft_fares"
rowspan="1" colspan="1"
aria-label="price: activate to sort column ascending">
price (default)
</th>
<th class="sorting" tabindex="0" aria-controls="aircraft_fares"
rowspan="1" colspan="1"
aria-label="cost: activate to sort column ascending">
cost (default)
</th>
<tr>
<th>name</th>
<th>code</th>
<th>capacity (default)</th>
<th>price (default)</th>
<th>cost (default)</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach($subfleet->fares as $atf)
<tr role="row" class="@if ($loop->iteration % 2) even @else odd @endif">
<tr>
<td class="sorting_1">{!! $atf->name !!}</td>
<td style="text-align: center;">{!! $atf->code !!}</td>
<td><a href="#" data-pk="{!! $atf->id !!}" data-name="capacity">{!! $atf->pivot->capacity !!}</a>
@@ -65,7 +53,7 @@
<hr />
<div class="row">
<div class="col-xs-12">
<div class="input-group input-group-lg pull-right">
<div class="text-right">
{!! Form::open(['url' => '/admin/subfleets/'.$subfleet->id.'/fares',
'method' => 'post',
'class' => 'rm_fare form-inline'