#11 assign/remove fares from aircraft
This commit is contained in:
@@ -16,6 +16,20 @@ class AircraftController extends BaseController
|
|||||||
/** @var AircraftRepository */
|
/** @var AircraftRepository */
|
||||||
private $aircraftRepository, $fareRepository;
|
private $aircraftRepository, $fareRepository;
|
||||||
|
|
||||||
|
protected function getAvailFares($all_fares, $attached_fares)
|
||||||
|
{
|
||||||
|
$retval = [];
|
||||||
|
$avail_fares = $all_fares->except($attached_fares->modelKeys());
|
||||||
|
foreach ($avail_fares as $fare) {
|
||||||
|
$retval[$fare->id] = $fare->name.
|
||||||
|
' (price: '.$fare->price.
|
||||||
|
', cost: '.$fare->cost.
|
||||||
|
', capacity: '.$fare->capacity.')';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $retval;
|
||||||
|
}
|
||||||
|
|
||||||
public function __construct(AircraftRepository $aircraftRepo, FareRepository $fareRepo)
|
public function __construct(AircraftRepository $aircraftRepo, FareRepository $fareRepo)
|
||||||
{
|
{
|
||||||
$this->fareRepository = $fareRepo;
|
$this->fareRepository = $fareRepo;
|
||||||
@@ -69,7 +83,7 @@ class AircraftController extends BaseController
|
|||||||
|
|
||||||
$attached_fares = $aircraft->fares;
|
$attached_fares = $aircraft->fares;
|
||||||
$all_fares = $this->fareRepository->all();
|
$all_fares = $this->fareRepository->all();
|
||||||
$avail_fares = $all_fares->except($attached_fares->modelKeys());
|
$avail_fares = $this->getAvailFares($all_fares, $attached_fares);
|
||||||
|
|
||||||
return view('admin.aircraft.show')
|
return view('admin.aircraft.show')
|
||||||
->with('aircraft', $aircraft)
|
->with('aircraft', $aircraft)
|
||||||
@@ -132,9 +146,10 @@ class AircraftController extends BaseController
|
|||||||
|
|
||||||
protected function return_fares_view($aircraft)
|
protected function return_fares_view($aircraft)
|
||||||
{
|
{
|
||||||
|
$aircraft->refresh();
|
||||||
$attached_fares = $aircraft->fares;
|
$attached_fares = $aircraft->fares;
|
||||||
$all_fares = $this->fareRepository->all();
|
$all_fares = $this->fareRepository->all();
|
||||||
$avail_fares = $all_fares->except($attached_fares->modelKeys());
|
$avail_fares = $this->getAvailFares($all_fares, $attached_fares);
|
||||||
|
|
||||||
return view('admin.aircraft.fares')
|
return view('admin.aircraft.fares')
|
||||||
->with('aircraft', $aircraft)
|
->with('aircraft', $aircraft)
|
||||||
@@ -151,11 +166,15 @@ class AircraftController extends BaseController
|
|||||||
return view('admin.aircraft.fares')->with('fares', []);
|
return view('admin.aircraft.fares')->with('fares', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$fare_svc = app('App\Services\FareService');
|
||||||
|
|
||||||
// associate or dissociate the fare with this aircraft
|
// associate or dissociate the fare with this aircraft
|
||||||
if ($request->isMethod('post') || $request->isMethod('put')) {
|
if ($request->isMethod('post') || $request->isMethod('put')) {
|
||||||
// add
|
$fare = $this->fareRepository->findWithoutFail($request->fare_id);
|
||||||
|
$fare_svc->setForAircraft($aircraft, $fare);
|
||||||
} elseif ($request->isMethod('delete')) {
|
} elseif ($request->isMethod('delete')) {
|
||||||
print_r($request->request);
|
$fare = $this->fareRepository->findWithoutFail($request->fare_id);
|
||||||
|
$fare_svc->delFromAircraft($aircraft, $fare);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->return_fares_view($aircraft);
|
return $this->return_fares_view($aircraft);
|
||||||
|
|||||||
@@ -56,5 +56,25 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<hr />
|
<hr />
|
||||||
{!! $avail_fares !!}
|
<div class="row">
|
||||||
|
<div class="col-xs-12" style="text-align: right;">
|
||||||
|
<div class="input-group input-group-lg">
|
||||||
|
{!! Form::open(['url' => '/admin/aircraft/'.$aircraft->id.'/fares',
|
||||||
|
'method' => 'post',
|
||||||
|
'class' => 'rm_fare form-inline'
|
||||||
|
])
|
||||||
|
!!}
|
||||||
|
{!! Form::select('fare_id', $avail_fares, null, [
|
||||||
|
'placeholder' => 'Select Fare',
|
||||||
|
'class' => 'ac-fare-dropdown form-control input-lg',
|
||||||
|
|
||||||
|
])
|
||||||
|
!!}
|
||||||
|
{!! Form::button('<i class="glyphicon glyphicon-plus"></i> add',
|
||||||
|
['type' => 'submit',
|
||||||
|
'class' => 'btn btn-success btn-s']) !!}
|
||||||
|
{!! Form::close() !!}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -24,8 +24,8 @@
|
|||||||
@section('scripts')
|
@section('scripts')
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
$(".ac-fare-dropdown").select2();
|
||||||
$(document).on('submit', 'form.rm_fare', function(event) {
|
$(document).on('submit', 'form.rm_fare', function(event) {
|
||||||
console.log('saving!');
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
$.pjax.submit(event, '#aircraft_fares_wrapper', {push: false});
|
$.pjax.submit(event, '#aircraft_fares_wrapper', {push: false});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,9 +3,11 @@
|
|||||||
<div class="box box-solid">
|
<div class="box box-solid">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
{{--<i class="fa fa-text-width"></i>--}}
|
{{--<i class="fa fa-text-width"></i>--}}
|
||||||
<h3 class="box-title">{!! Form::label('icao', 'ICAO:') !!}</h3>
|
<h3 class="box-title">{!! Form::label('icao', 'ICAO') !!}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
<p class="lead">{!! $aircraft->icao !!}/<strong>{!! $aircraft->class->code !!}</strong> ({!! $aircraft->class->name !!})</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body"><p class="lead">{!! $aircraft->icao !!}</p></div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -14,7 +16,7 @@
|
|||||||
<div class="box box-solid">
|
<div class="box box-solid">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
{{--<i class="fa fa-text-width"></i>--}}
|
{{--<i class="fa fa-text-width"></i>--}}
|
||||||
<h3 class="box-title">{!! Form::label('name', 'Name:') !!}</h3>
|
<h3 class="box-title">{!! Form::label('name', 'Name') !!}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body"><p class="lead">{!! $aircraft->name !!}</p></div>
|
<div class="box-body"><p class="lead">{!! $aircraft->name !!}</p></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -25,9 +27,10 @@
|
|||||||
<div class="box box-solid">
|
<div class="box box-solid">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
{{--<i class="fa fa-text-width"></i>--}}
|
{{--<i class="fa fa-text-width"></i>--}}
|
||||||
<h3 class="box-title">{!! Form::label('registration', 'Registration:') !!}</h3>
|
<h3 class="box-title">{!! Form::label('registration', 'Registration') !!}/
|
||||||
|
{!! Form::label('tail_number', 'Tail Number') !!}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body"><p class="lead">{!! $aircraft->registration !!}</p></div>
|
<div class="box-body"><p class="lead">{!! $aircraft->registration !!}/{!! $aircraft->tail_number !!}</p></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user