#21 file PIREP; populate custom fields and set correct status
This commit is contained in:
parent
2c41144c61
commit
0d29369e54
@ -67,11 +67,13 @@ class PirepController extends Controller
|
||||
|
||||
public function create()
|
||||
{
|
||||
$aircraft = $this->aircraftList();
|
||||
$airports = $this->airportList();
|
||||
|
||||
return $this->view('pireps.create', [
|
||||
'airports' => $airports,
|
||||
'airlines' => Airline::all()->pluck('name', 'id'),
|
||||
'aircraft' => $this->aircraftList(),
|
||||
'aircraft' => $aircraft,
|
||||
'pirepfields' => PirepField::all(),
|
||||
'fieldvalues' => [],
|
||||
]);
|
||||
@ -79,7 +81,39 @@ class PirepController extends Controller
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$pirep_fields = $request->all();
|
||||
|
||||
// Create the main PIREP
|
||||
$pirep = new Pirep($pirep_fields);
|
||||
|
||||
// Any special fields
|
||||
$pirep->pilot()->associate(Auth::user());
|
||||
$pirep->flight_time = ((int)$pirep_fields['hours'] * 60 * 60)
|
||||
+ ((int)$pirep_fields['minutes'] * 60);
|
||||
|
||||
// The custom fields from the form
|
||||
$custom_fields = [];
|
||||
foreach($pirep_fields as $field_name => $field_val)
|
||||
{
|
||||
if (strpos($field_name, 'field_') === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$field_id = explode('field_', $field_name)[1];
|
||||
$cfield = PirepField::find($field_id);
|
||||
|
||||
$custom_fields[] = [
|
||||
'name' => $cfield->name,
|
||||
'value' => $field_val,
|
||||
'source' => config('enums.sources.MANUAL')
|
||||
];
|
||||
}
|
||||
|
||||
$pirepSvc = app('\App\Services\PIREPService');
|
||||
$pirep = $pirepSvc->create($pirep, $custom_fields);
|
||||
|
||||
//Flash::success('PIREP submitted successfully!');
|
||||
return redirect(route('frontend.pireps.index'));
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
|
@ -25,11 +25,12 @@ class Pirep extends Model
|
||||
= [
|
||||
'user_id',
|
||||
'flight_id',
|
||||
'flight_number',
|
||||
'route_code',
|
||||
'route_leg',
|
||||
'airline_id',
|
||||
'aircraft_id',
|
||||
'flight_time',
|
||||
'route_code',
|
||||
'route_leg',
|
||||
'dpt_airport_id',
|
||||
'arr_airport_id',
|
||||
'fuel_used',
|
||||
|
@ -26,10 +26,11 @@ class PIREPService extends BaseService
|
||||
*
|
||||
* @return Pirep
|
||||
*/
|
||||
public function create(
|
||||
Pirep $pirep,
|
||||
array $field_values=[]
|
||||
): Pirep {
|
||||
public function create(Pirep $pirep, array $field_values): Pirep {
|
||||
|
||||
if($field_values == null) {
|
||||
$field_values = [];
|
||||
}
|
||||
|
||||
# Figure out what default state should be. Look at the default
|
||||
# behavior from the rank that the pilot is assigned to
|
||||
@ -43,25 +44,24 @@ class PIREPService extends BaseService
|
||||
$pirep = $this->accept($pirep);
|
||||
}
|
||||
|
||||
$pirep->save();
|
||||
$pirep->refresh();
|
||||
|
||||
foreach ($field_values as $fv) {
|
||||
$v = new PirepFieldValues();
|
||||
$v->pirep_id = $pirep->id;
|
||||
$v->name = $fv['name'];
|
||||
$v->value = $fv['value'];
|
||||
$v->source = $fv['source'];
|
||||
$v->save();
|
||||
}
|
||||
|
||||
# TODO: Financials even if it's rejected, log the expenses
|
||||
# only update the pilot last state if they are accepted
|
||||
if ($default_status == config('enums.pirep_status.ACCEPTED')) {
|
||||
$this->setPilotState($pirep);
|
||||
}
|
||||
|
||||
$pirep->save();
|
||||
|
||||
# update pilot information
|
||||
$pilot = $pirep->pilot;
|
||||
$pilot->refresh();
|
||||
|
||||
$pilot->curr_airport_id = $pirep->arr_airport_id;
|
||||
$pilot->last_pirep_id = $pirep->id;
|
||||
$pilot->save();
|
||||
# TODO: Emit filed event. Do financials through that
|
||||
|
||||
return $pirep;
|
||||
}
|
||||
@ -124,6 +124,7 @@ class PIREPService extends BaseService
|
||||
# Change the status
|
||||
$pirep->status = config('enums.pirep_status.ACCEPTED');
|
||||
$pirep->save();
|
||||
$pirep->refresh();
|
||||
|
||||
return $pirep;
|
||||
}
|
||||
@ -149,10 +150,19 @@ class PIREPService extends BaseService
|
||||
# Change the status
|
||||
$pirep->status = config('enums.pirep_status.REJECTED');
|
||||
$pirep->save();
|
||||
$pirep->refresh();
|
||||
|
||||
return $pirep;
|
||||
}
|
||||
|
||||
public function setPilotState($pirep) {
|
||||
$pilot = $pirep->pilot;
|
||||
$pilot->refresh();
|
||||
$pilot->curr_airport_id = $pirep->arr_airport_id;
|
||||
$pilot->last_pirep_id = $pirep->id;
|
||||
$pilot->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate all of the finances for a PIREP
|
||||
* @param Pirep $pirep
|
||||
|
@ -17,8 +17,9 @@ class CreatePirepsTable extends Migration
|
||||
$table->uuid('id');
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->integer('airline_id')->unsigned();
|
||||
$table->uuid('flight_id')->nullable();
|
||||
$table->integer('aircraft_id')->nullable();
|
||||
$table->uuid('flight_id')->nullable();
|
||||
$table->string('flight_number', 10)->nullable();
|
||||
$table->string('route_code', 5)->nullable();
|
||||
$table->string('route_leg', 5)->nullable();
|
||||
$table->integer('dpt_airport_id')->unsigned();
|
||||
@ -26,7 +27,6 @@ class CreatePirepsTable extends Migration
|
||||
$table->double('flight_time', 19, 2)->unsigned();
|
||||
$table->double('gross_weight', 19, 2)->nullable();
|
||||
$table->double('fuel_used', 19, 2)->nullable();
|
||||
$table->integer('level')->unsigned();
|
||||
$table->string('route')->nullable();
|
||||
$table->string('notes')->nullable();
|
||||
$table->tinyInteger('source')->default(0);
|
||||
|
@ -232,7 +232,6 @@ pireps:
|
||||
dpt_airport_id: 1
|
||||
arr_airport_id: 2
|
||||
flight_time: 21600 # 6 hours
|
||||
level: 320
|
||||
status: -1
|
||||
notes: just a pilot report
|
||||
- id: pirepid_2
|
||||
@ -243,7 +242,6 @@ pireps:
|
||||
dpt_airport_id: 2
|
||||
arr_airport_id: 1
|
||||
flight_time: 21600 # 6 hours
|
||||
level: 320
|
||||
status: -1
|
||||
notes: just a pilot report
|
||||
|
||||
|
@ -1,79 +1,110 @@
|
||||
<!-- Flight Id Field -->
|
||||
{{--<div class="form-group col-sm-6">
|
||||
{!! Form::label('flight_id', 'Flight ID:') !!}
|
||||
{!! Form::text('flight_id', null, ['class' => 'form-control']) !!}
|
||||
</div>--}}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<table class="table table-full-width">
|
||||
<thead>
|
||||
|
||||
<div class="col-sm-6">
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Airline</td>
|
||||
<td>
|
||||
<div class="input-group form-group">
|
||||
{!! Form::select('airline_id', $airlines, null, ['class' => 'custom-select select2']) !!}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<p class="description">Airline</p>
|
||||
<div class="input-group form-group">
|
||||
{!! Form::select('airline_id', $airlines, null, ['class' => 'custom-select select2']) !!}
|
||||
</div>
|
||||
<tr>
|
||||
<td>Flight Number/Code/Leg</td>
|
||||
<td>
|
||||
<div class="input-group form-group" style="max-width: 400px;">
|
||||
{!! Form::text('flight_number', null, ['placeholder' => 'Flight Number', 'class' => 'form-control']) !!}
|
||||
{!! Form::text('route_code', null, ['placeholder' => 'Code (optional)', 'class' => 'form-control']) !!}
|
||||
{!! Form::text('route_leg', null, ['placeholder' => 'Leg (optional)', 'class' => 'form-control']) !!}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<p class="description">Aircraft</p>
|
||||
<div class="input-group form-group">
|
||||
{!! Form::select('aircraft_id', $aircraft, null, ['class' => 'custom-select select2']) !!}
|
||||
</div>
|
||||
<tr>
|
||||
<td>Aircraft</td>
|
||||
<td>
|
||||
<div class="input-group form-group">
|
||||
{!! Form::select('aircraft_id', $aircraft, null, ['class' => 'custom-select select2']) !!}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<p class="description">Origin Airport</p>
|
||||
<div class="input-group form-group">
|
||||
{!! Form::select('dep_airport_id', $airports, null, ['class' => 'custom-select select2']) !!}
|
||||
</div>
|
||||
<tr>
|
||||
<td>Origin Airport</td>
|
||||
<td>
|
||||
<div class="input-group form-group">
|
||||
{!! Form::select('dpt_airport_id', $airports, null, ['class' => 'custom-select select2']) !!}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<p class="description">Arrival Airport</p>
|
||||
<div class="input-group form-group">
|
||||
{!! Form::select('arr_airport_id', $airports, null, ['class' => 'custom-select select2']) !!}
|
||||
</div>
|
||||
<tr>
|
||||
<td>Arrival Airport</td>
|
||||
<td>
|
||||
<div class="input-group form-group">
|
||||
{!! Form::select('arr_airport_id', $airports, null, ['class' => 'custom-select select2']) !!}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Flight Time Field -->
|
||||
<p class="description">Flight Time</p>
|
||||
<div class="input-group form-group-no-border">
|
||||
{!! Form::text('hours', null, ['class' => 'form-control', 'placeholder' => 'hours']) !!}
|
||||
</div>
|
||||
<div class="input-group form-group-no-border">
|
||||
{!! Form::text('minutes', null, ['class' => 'form-control', 'placeholder' => 'minutes']) !!}
|
||||
</div>
|
||||
<tr>
|
||||
<td class="align-text-top">Flight Time</td>
|
||||
<td>
|
||||
<div class="input-group" style="max-width: 200px;">
|
||||
{!! Form::number('hours', null, ['class' => 'form-control', 'placeholder' => 'hours']) !!}
|
||||
{!! Form::number('minutes', null, ['class' => 'form-control', 'placeholder' => 'minutes']) !!}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Level Field -->
|
||||
<p class="description">Flight Level</p>
|
||||
<div class="input-group form-group">
|
||||
<span class="input-group-addon">
|
||||
<i class="now-ui-icons users_single-02"></i>
|
||||
</span>
|
||||
{!! Form::number('level', null, ['class' => 'form-control', 'placeholder' => 'Flight Level']) !!}
|
||||
</div>
|
||||
<tr>
|
||||
<td class="align-text-top">Route</td>
|
||||
<td>
|
||||
<div class="input-group form-group">
|
||||
{!! Form::textarea('route', null, ['class' => 'form-control', 'placeholder' => 'Route']) !!}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- Route Field -->
|
||||
<p class="description">Route</p>
|
||||
<div class="input-group form-group">
|
||||
{{--
|
||||
Write out the custom fields, and label if they're required
|
||||
--}}
|
||||
@foreach($pirepfields as $field)
|
||||
<tr>
|
||||
<td>
|
||||
{!! $field->name !!}
|
||||
<span class="label label-danger">required</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="input-group form-group">
|
||||
<!--<span class="input-group-addon">
|
||||
<i class="now-ui-icons users_single-02"></i>
|
||||
</span>-->
|
||||
{!! Form::text('field_'.$field->id, null, [
|
||||
'class' => 'form-control',
|
||||
'required' => $field->required,
|
||||
]) !!}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
||||
{!! Form::textarea('route', null, ['class' => 'form-control', 'placeholder' => 'Route']) !!}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
|
||||
<!-- optional fields -->
|
||||
|
||||
@foreach($pirepfields as $field)
|
||||
<p class="description text-uppercase">{!! $field->name !!}</p>
|
||||
<div class="input-group form-group">
|
||||
<!--<span class="input-group-addon">
|
||||
<i class="now-ui-icons users_single-02"></i>
|
||||
</span>-->
|
||||
{!! Form::text('field_'.$field->id, null, [
|
||||
'class' => 'form-control',
|
||||
'required' => $field->required,
|
||||
]) !!}
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
<p class="description">Notes</p>
|
||||
<div class="input-group form-group">
|
||||
{!! Form::textarea('notes', null, ['class' => 'form-control', 'placeholder' => 'Notes']) !!}
|
||||
</div>
|
||||
<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>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-12">
|
||||
|
@ -4,8 +4,13 @@
|
||||
<div class="row">
|
||||
<div class="col-sm-2 text-center">
|
||||
<h5>
|
||||
<a class="text-c" href="{!! route('frontend.flights.show', [$pirep->flight_id]) !!}">
|
||||
{!! $pirep->airline->code !!}{!! $pirep->flight->flight_number !!}
|
||||
<a class="text-c" href="{!! route('frontend.pireps.show', [$pirep->id]) !!}">
|
||||
{!! $pirep->airline->code !!}
|
||||
@if($pirep->flight_id)
|
||||
{!! $pirep->flight->flight_number !!}
|
||||
@else
|
||||
{!! $pirep->flight_number !!}
|
||||
@endif
|
||||
</a>
|
||||
</h5>
|
||||
<div>
|
||||
|
Loading…
Reference in New Issue
Block a user