Add the acars and manual payrates in the rank/subfleet forms

This commit is contained in:
Nabeel Shahzad 2018-02-26 19:14:10 -06:00
parent f6ec647eb6
commit cdd5fc749c
11 changed files with 95 additions and 20 deletions

View File

@ -57,8 +57,8 @@ class CreateSubfleetTables extends Migration
Schema::create('subfleet_rank', function(Blueprint $table) { Schema::create('subfleet_rank', function(Blueprint $table) {
$table->unsignedInteger('rank_id'); $table->unsignedInteger('rank_id');
$table->unsignedInteger('subfleet_id'); $table->unsignedInteger('subfleet_id');
$table->unsignedDecimal('acars_pay')->nullable(); $table->string('acars_pay')->nullable();
$table->unsignedDecimal('manual_pay')->nullable(); $table->string('manual_pay')->nullable();
$table->primary(['rank_id', 'subfleet_id']); $table->primary(['rank_id', 'subfleet_id']);
$table->index(['subfleet_id', 'rank_id']); $table->index(['subfleet_id', 'rank_id']);

View File

@ -207,6 +207,13 @@ class RankController extends BaseController
$rank->subfleets()->syncWithoutDetaching([$request->subfleet_id]); $rank->subfleets()->syncWithoutDetaching([$request->subfleet_id]);
} }
elseif($request->isMethod('put')) {
$override = [];
$subfleet = $this->subfleetRepo->find($request->input('subfleet_id'));
$override[$request->name] = $request->value;
$rank->subfleets()->updateExistingPivot($subfleet->id, $override);
}
// remove aircraft from flight // remove aircraft from flight
elseif ($request->isMethod('delete')) { elseif ($request->isMethod('delete')) {
$rank->subfleets()->detach($request->subfleet_id); $rank->subfleets()->detach($request->subfleet_id);

View File

@ -274,6 +274,13 @@ class SubfleetController extends BaseController
$subfleet->ranks()->syncWithoutDetaching([$request->input('rank_id')]); $subfleet->ranks()->syncWithoutDetaching([$request->input('rank_id')]);
} }
elseif ($request->isMethod('put')) {
$override = [];
$rank = $this->fareRepo->find($request->input('rank_id'));
$override[$request->name] = $request->value;
$subfleet->ranks()->updateExistingPivot($rank->id, $override);
}
// dissassociate fare from teh aircraft // dissassociate fare from teh aircraft
elseif ($request->isMethod('delete')) { elseif ($request->isMethod('delete')) {
$subfleet->ranks()->detach($request->input('rank_id')); $subfleet->ranks()->detach($request->input('rank_id'));
@ -305,21 +312,21 @@ class SubfleetController extends BaseController
* update specific fare data * update specific fare data
*/ */
if ($request->isMethod('post')) { if ($request->isMethod('post')) {
$fare = $this->fareRepo->findWithoutFail($request->fare_id); $fare = $this->fareRepo->find($request->fare_id);
$this->fareSvc->setForSubfleet($subfleet, $fare); $this->fareSvc->setForSubfleet($subfleet, $fare);
} }
// update the pivot table with overrides for the fares // update the pivot table with overrides for the fares
elseif ($request->isMethod('put')) { elseif ($request->isMethod('put')) {
$override = []; $override = [];
$fare = $this->fareRepo->findWithoutFail($request->fare_id); $fare = $this->fareRepo->find($request->fare_id);
$override[$request->name] = $request->value; $override[$request->name] = $request->value;
$this->fareSvc->setForSubfleet($subfleet, $fare, $override); $this->fareSvc->setForSubfleet($subfleet, $fare, $override);
} }
// dissassociate fare from teh aircraft // dissassociate fare from teh aircraft
elseif ($request->isMethod('delete')) { elseif ($request->isMethod('delete')) {
$fare = $this->fareRepo->findWithoutFail($request->fare_id); $fare = $this->fareRepo->find($request->fare_id);
$this->fareSvc->delFareFromSubfleet($subfleet, $fare); $this->fareSvc->delFareFromSubfleet($subfleet, $fare);
} }

View File

@ -47,7 +47,7 @@ Route::group([
# subfleet # subfleet
Route::resource('subfleets', 'SubfleetController'); Route::resource('subfleets', 'SubfleetController');
Route::match(['get', 'post', 'put', 'delete'], 'subfleets/{id}/fares', 'SubfleetController@fares'); Route::match(['get', 'post', 'put', 'delete'], 'subfleets/{id}/fares', 'SubfleetController@fares');
Route::match(['get', 'post', 'delete'], 'subfleets/{id}/ranks', 'SubfleetController@ranks'); Route::match(['get', 'post', 'put', 'delete'], 'subfleets/{id}/ranks', 'SubfleetController@ranks');
Route::resource('users', 'UserController'); Route::resource('users', 'UserController');
Route::get('users/{id}/regen_apikey', Route::get('users/{id}/regen_apikey',

View File

@ -14,7 +14,8 @@
<div class="header"> <div class="header">
<h3>subfleets</h3> <h3>subfleets</h3>
@component('admin.components.info') @component('admin.components.info')
These are the subfleets this rank is allowed to use These are the subfleets this rank is allowed to use. The pay can be
set as a fixed amount, or a percentage of the rank's base payrate above
@endcomponent @endcomponent
</div> </div>
<div class="row"> <div class="row">

View File

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

View File

@ -1,7 +1,26 @@
@section('scripts') @section('scripts')
<script> <script>
function setEditable() {
$('#subfleets-table a').editable({
type: 'text',
mode: 'inline',
emptytext: 'inherited',
url: '{!! url('/admin/ranks/'.$rank->id.'/subfleets') !!}',
title: 'Enter override value',
ajaxOptions: {'type': 'put'},
params: function (params) {
return {
subfleet_id: params.pk,
name: params.name,
value: params.value
}
}
});
}
$(document).ready(function () { $(document).ready(function () {
$(".select2").select2();
setEditable();
$(document).on('submit', 'form.pjax_form', function (event) { $(document).on('submit', 'form.pjax_form', function (event) {
event.preventDefault(); event.preventDefault();
@ -10,6 +29,7 @@ $(document).ready(function () {
$(document).on('pjax:complete', function () { $(document).on('pjax:complete', function () {
$(".select2").select2(); $(".select2").select2();
setEditable();
}); });
}); });
</script> </script>

View File

@ -3,15 +3,24 @@
<thead> <thead>
<th>Airline</th> <th>Airline</th>
<th>Name</th> <th>Name</th>
<th>Type</th> <th style="text-align: center;">ACARS Pay</th>
<th style="text-align: center;">Manual Pay</th>
<th style="text-align: center;">Actions</th> <th style="text-align: center;">Actions</th>
</thead> </thead>
<tbody> <tbody>
@foreach($rank->subfleets as $sf) @foreach($rank->subfleets as $sf)
<tr> <tr>
<td>{!! $sf->airline->name !!}</td> <td>{!! $sf->airline->name !!}</td>
<td>{!! $sf->name !!}</td> <td>{!! $sf->name !!} ({!! $sf->type !!})</td>
<td>{!! $sf->type !!}</td> <td style="text-align: center;">
<a href="#" data-pk="{!! $sf->id !!}"
data-name="acars_pay">{!! $sf->pivot->acars_pay !!}</a>
</td>
<td style="text-align: center;">
<a href="#" data-pk="{!! $sf->id !!}"
data-name="manual_pay">{!! $sf->pivot->manual_pay !!}</a>
</td>
<td style="width: 10%; text-align: center;" class="form-inline"> <td style="width: 10%; text-align: center;" class="form-inline">
{!! Form::open(['url' => '/admin/ranks/'.$rank->id.'/subfleets', 'method' => 'delete', 'class' => 'pjax_form']) !!} {!! Form::open(['url' => '/admin/ranks/'.$rank->id.'/subfleets', 'method' => 'delete', 'class' => 'pjax_form']) !!}
{!! Form::hidden('subfleet_id', $sf->id) !!} {!! Form::hidden('subfleet_id', $sf->id) !!}

View File

@ -4,17 +4,18 @@
@component('admin.components.info') @component('admin.components.info')
Fares assigned to the current subfleet. These can be overridden, Fares assigned to the current subfleet. These can be overridden,
otherwise, the value used is the default, which comes from the fare. otherwise, the value used is the default, which comes from the fare.
The pay can be set as a fixed amount, or a percentage of the default rate
@endcomponent @endcomponent
</div> </div>
<br /> <br />
<table id="aircraft_fares" class="table table-hover"> <table id="aircraft_fares" class="table table-hover">
<thead> <thead>
<tr> <tr>
<th>name</th> <th>Name</th>
<th style="text-align: center;">code</th> <th style="text-align: center;">Code</th>
<th style="text-align: center;">capacity (default)</th> <th style="text-align: center;">Capacity (default)</th>
<th style="text-align: center;">price (default)</th> <th style="text-align: center;">Price (default)</th>
<th style="text-align: center;">cost (default)</th> <th style="text-align: center;">Cost (default)</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>

View File

@ -2,14 +2,18 @@
<div class="header"> <div class="header">
<h3>ranks</h3> <h3>ranks</h3>
@component('admin.components.info') @component('admin.components.info')
These ranks are allowed to fly aircraft in this subfleet These ranks are allowed to fly aircraft in this subfleet. The pay can be
set as a fixed amount, or a percentage of the rank's base payrate
@endcomponent @endcomponent
</div> </div>
<br /> <br />
<table id="subfleet_ranks" class="table table-hover dataTable"> <table id="subfleet_ranks" class="table table-hover dataTable">
<thead> <thead>
<tr> <tr>
<th>name</th> <th>Name</th>
<th style="text-align: center;">Base rate</th>
<th style="text-align: center;">ACARS pay</th>
<th style="text-align: center;">Manual pay</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
@ -17,6 +21,17 @@
@foreach($subfleet->ranks as $rank) @foreach($subfleet->ranks as $rank)
<tr> <tr>
<td class="sorting_1">{!! $rank->name !!}</td> <td class="sorting_1">{!! $rank->name !!}</td>
<td style="text-align: center;">{!! $rank->base_pay_rate ?: '-' !!}</td>
<td style="text-align: center;">
<a href="#" data-pk="{!! $rank->id !!}"
data-name="acars_pay">{!! $rank->pivot->acars_pay !!}</a>
</td>
<td style="text-align: center;">
<a href="#" data-pk="{!! $rank->id !!}"
data-name="manual_pay">{!! $rank->pivot->manual_pay !!}</a>
</td>
<td style="text-align: right; width:3%;"> <td style="text-align: right; width:3%;">
{!! Form::open(['url' => '/admin/subfleets/'.$subfleet->id.'/ranks', {!! Form::open(['url' => '/admin/subfleets/'.$subfleet->id.'/ranks',
'method' => 'delete', 'method' => 'delete',

View File

@ -4,7 +4,7 @@ function setEditable() {
$('#aircraft_fares a').editable({ $('#aircraft_fares a').editable({
type: 'text', type: 'text',
mode: 'inline', mode: 'inline',
emptytext: 'default', emptytext: 'inherited',
url: '{!! url('/admin/subfleets/'.$subfleet->id.'/fares') !!}', url: '{!! url('/admin/subfleets/'.$subfleet->id.'/fares') !!}',
title: 'Enter override value', title: 'Enter override value',
ajaxOptions: {'type': 'put'}, ajaxOptions: {'type': 'put'},
@ -16,6 +16,22 @@ function setEditable() {
} }
} }
}); });
$('#subfleet_ranks a').editable({
type: 'text',
mode: 'inline',
emptytext: 'inherited',
url: '{!! url('/admin/subfleets/'.$subfleet->id.'/ranks') !!}',
title: 'Enter override value',
ajaxOptions: {'type': 'put'},
params: function (params) {
return {
rank_id: params.pk,
name: params.name,
value: params.value
}
}
});
} }
$(document).ready(function() { $(document).ready(function() {