diff --git a/app/Http/Controllers/Admin/FlightController.php b/app/Http/Controllers/Admin/FlightController.php index d9b52404..9202463c 100644 --- a/app/Http/Controllers/Admin/FlightController.php +++ b/app/Http/Controllers/Admin/FlightController.php @@ -50,8 +50,9 @@ class FlightController extends BaseController { $this->flightRepository->pushCriteria(new RequestCriteria($request)); $flights = $this->flightRepository->all(); - return view('admin.flights.index') - ->with('flights', $flights); + return view('admin.flights.index', [ + 'flights' => $flights, + ]); } /** @@ -78,7 +79,6 @@ class FlightController extends BaseController $flight = $this->flightRepository->create($input); Flash::success('Flight saved successfully.'); - return redirect(route('admin.flights.index')); } @@ -99,9 +99,10 @@ class FlightController extends BaseController } $avail_subfleets = $this->getAvailSubfleets($flight); - return view('admin.flights.show') - ->with('flight', $flight) - ->with('avail_subfleets', $avail_subfleets); + return view('admin.flights.show', [ + 'flight' => $flight, + 'avail_subfleets' => $avail_subfleets, + ]); } /** @@ -120,7 +121,11 @@ class FlightController extends BaseController return redirect(route('admin.flights.index')); } - return view('admin.flights.edit')->with('flight', $flight); + $avail_subfleets = $this->getAvailSubfleets($flight); + return view('admin.flights.edit', [ + 'flight' => $flight, + 'avail_subfleets' => $avail_subfleets, + ]); } /** @@ -171,9 +176,10 @@ class FlightController extends BaseController protected function return_subfleet_view($flight) { $avail_subfleets = $this->getAvailSubfleets($flight); - return view('admin.flights.subfleets') - ->with('flight', $flight) - ->with('avail_subfleets', $avail_subfleets); + return view('admin.flights.subfleets', [ + 'flight' => $flight, + 'avail_subfleets' => $avail_subfleets, + ]); } public function subfleets(Request $request) diff --git a/app/Http/Controllers/Admin/RankController.php b/app/Http/Controllers/Admin/RankController.php index 559be564..b0fb0b74 100644 --- a/app/Http/Controllers/Admin/RankController.php +++ b/app/Http/Controllers/Admin/RankController.php @@ -5,7 +5,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreateRankRequest; use App\Http\Requests\UpdateRankRequest; use App\Repositories\RankRepository; -use App\Http\Controllers\AppBaseController as InfyOmBaseController; +use App\Repositories\SubfleetRepository; use Illuminate\Http\Request; use Flash; use Prettus\Repository\Criteria\RequestCriteria; @@ -14,11 +14,28 @@ use Response; class RankController extends BaseController { /** @var RankRepository */ - private $rankRepository; + private $rankRepository, $subfleetRepo; - public function __construct(RankRepository $rankingRepo) + public function __construct( + RankRepository $rankingRepo, + SubfleetRepository $subfleetRepo + ) { $this->rankRepository = $rankingRepo; + $this->subfleetRepo = $subfleetRepo; + } + + protected function getAvailSubfleets($rank) + { + $retval = []; + $all_subfleets = $this->subfleetRepo->all(); + $avail_subfleets = $all_subfleets->except($rank->subfleets->modelKeys()); + foreach ($avail_subfleets as $subfleet) { + $retval[$subfleet->id] = $subfleet->name. + ' (airline: '.$subfleet->airline->code.')'; + } + + return $retval; } /** @@ -32,8 +49,9 @@ class RankController extends BaseController $this->rankRepository->pushCriteria(new RequestCriteria($request)); $ranks = $this->rankRepository->all(); - return view('admin.ranks.index') - ->with('ranks', $ranks); + return view('admin.ranks.index', [ + 'ranks' => $ranks, + ]); } /** @@ -48,12 +66,10 @@ class RankController extends BaseController /** * Store a newly created Ranking in storage. - * * @param CreateRankRequest $request - * * @return Response */ - public function store(Request $request) + public function store(CreateRankRequest $request) { $input = $request->all(); @@ -61,8 +77,9 @@ class RankController extends BaseController Flash::success('Ranking saved successfully.'); $ranks = $this->rankRepository->all(); - return view('admin.ranks.table') - ->with('ranks', $ranks); + return view('admin.ranks.table', [ + 'ranks' => $ranks, + ]); } /** @@ -81,7 +98,9 @@ class RankController extends BaseController return redirect(route('admin.ranks.index')); } - return view('admin.ranks.show')->with('rank', $rank); + return view('admin.ranks.show', [ + 'rank' => $rank + ]); } /** @@ -100,7 +119,11 @@ class RankController extends BaseController return redirect(route('admin.ranks.index')); } - return view('admin.ranks.edit')->with('rank', $rank); + $avail_subfleets = $this->getAvailSubfleets($rank); + return view('admin.ranks.edit', [ + 'rank' => $rank, + 'avail_subfleets' => $avail_subfleets, + ]); } /** @@ -123,7 +146,6 @@ class RankController extends BaseController $rank = $this->rankRepository->update($request->all(), $id); Flash::success('Ranking updated successfully.'); - return redirect(route('admin.ranks.index')); } @@ -146,7 +168,38 @@ class RankController extends BaseController $this->rankRepository->delete($id); Flash::success('Ranking deleted successfully.'); - return redirect(route('admin.ranks.index')); } + + protected function return_subfleet_view($rank) + { + $avail_subfleets = $this->getAvailSubfleets($rank); + return view('admin.ranks.subfleets', [ + 'rank' => $rank, + 'avail_subfleets' => $avail_subfleets, + ]); + } + + public function subfleets(Request $request) + { + $id = $request->id; + + $rank = $this->rankRepository->findWithoutFail($id); + if (empty($rank)) { + Flash::error('Rank not found!'); + return redirect(route('admin.ranks.index')); + } + + // add aircraft to flight + if ($request->isMethod('post')) { + $rank->subfleets()->syncWithoutDetaching([$request->subfleet_id]); + } + + // remove aircraft from flight + elseif ($request->isMethod('delete')) { + $rank->subfleets()->detach($request->subfleet_id); + } + + return $this->return_subfleet_view($rank); + } } diff --git a/app/Services/PIREPService.php b/app/Services/PIREPService.php index 0057936e..bc36bea6 100644 --- a/app/Services/PIREPService.php +++ b/app/Services/PIREPService.php @@ -2,6 +2,9 @@ namespace App\Services; +use App\Models\Pirep; +use App\Models\PirepFieldValues; + use App\Repositories\PirepRepository; use App\Repositories\SubfleetRepository; @@ -21,7 +24,21 @@ class PIREPService extends BaseService { $this->pirepRepo = $pirepRepo; } - public function create() { + public function create( + Pirep $pirep, + array $field_values # PirepFieldValues + ) { + $pirep->save(); + + foreach($field_values as $fv) { + $v = new PirepFieldValues(); + $v->name = $fv['name']; + $v->value = $fv['value']; + $v->source = $fv['source']; + $v->save(); + } + + # TODO: Financials } } diff --git a/database/migrations/2017_06_23_011011_create_subfleets_table.php b/database/migrations/2017_06_23_011011_create_subfleets_table.php index 040eef34..10cebcf8 100644 --- a/database/migrations/2017_06_23_011011_create_subfleets_table.php +++ b/database/migrations/2017_06_23_011011_create_subfleets_table.php @@ -26,6 +26,14 @@ class CreateSubfleetsTable extends Migration $table->softDeletes(); }); + Schema::create('subfleet_expenses', function(Blueprint $table) { + $table->integer('subfleet_id')->unsigned(); + $table->string('name'); + $table->decimal('cost', 19, 2)->unsigned(); + + $table->primary(['subfleet_id', 'name']); + }); + Schema::create('subfleet_fare', function (Blueprint $table) { $table->integer('subfleet_id')->unsigned(); $table->integer('fare_id')->unsigned(); @@ -65,7 +73,9 @@ class CreateSubfleetsTable extends Migration public function down() { Schema::drop('subfleets'); - Schema::drop('subfleet_rank'); + Schema::drop('subfleet_expenses'); + Schema::drop('subfleet_fare'); Schema::drop('subfleet_flight'); + Schema::drop('subfleet_rank'); } } diff --git a/resources/views/admin/flights/edit.blade.php b/resources/views/admin/flights/edit.blade.php index 86a5b0bf..7512ce6a 100644 --- a/resources/views/admin/flights/edit.blade.php +++ b/resources/views/admin/flights/edit.blade.php @@ -17,5 +17,33 @@ +
Airline | +Name | +Type | +Actions | + + + @foreach($rank->subfleets as $sf) +
---|---|---|---|
{!! $sf->airline->name !!} | +{!! $sf->name !!} | +{!! $sf->type !!} | +
+ {!! Form::open(['url' => '/admin/ranks/'.$rank->id.'/subfleets', 'method' => 'delete', 'class' => 'pjax_form']) !!}
+ {!! Form::hidden('subfleet_id', $sf->id) !!}
+
+ {!! Form::button('',
+ ['type' => 'submit',
+ 'class' => 'btn btn-danger btn-xs'])
+ !!}
+
+ {!! Form::close() !!}
+ |
+