2017-06-23 09:55:45 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Http\Requests\CreateSubfleetRequest;
|
2018-03-23 06:17:37 +08:00
|
|
|
use App\Http\Requests\ImportRequest;
|
2017-06-23 09:55:45 +08:00
|
|
|
use App\Http\Requests\UpdateSubfleetRequest;
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Controller;
|
2018-02-21 12:33:09 +08:00
|
|
|
use App\Models\Airline;
|
|
|
|
use App\Models\Enums\FuelType;
|
2018-03-06 11:24:49 +08:00
|
|
|
use App\Models\Expense;
|
2018-02-21 12:33:09 +08:00
|
|
|
use App\Models\Subfleet;
|
2018-01-10 03:34:19 +08:00
|
|
|
use App\Repositories\AircraftRepository;
|
2017-06-25 00:09:27 +08:00
|
|
|
use App\Repositories\FareRepository;
|
2018-02-21 12:33:09 +08:00
|
|
|
use App\Repositories\RankRepository;
|
2017-06-23 09:55:45 +08:00
|
|
|
use App\Repositories\SubfleetRepository;
|
2018-03-23 06:59:10 +08:00
|
|
|
use App\Services\ExportService;
|
2018-01-08 00:38:16 +08:00
|
|
|
use App\Services\FareService;
|
2018-02-28 04:12:03 +08:00
|
|
|
use App\Services\FleetService;
|
2018-03-22 08:12:36 +08:00
|
|
|
use App\Services\ImportService;
|
2018-02-21 12:33:09 +08:00
|
|
|
use Flash;
|
|
|
|
use Illuminate\Http\Request;
|
2018-03-21 08:17:11 +08:00
|
|
|
use Log;
|
2018-02-21 12:33:09 +08:00
|
|
|
use Prettus\Repository\Criteria\RequestCriteria;
|
|
|
|
use Response;
|
2018-03-21 08:17:11 +08:00
|
|
|
use Storage;
|
2018-01-08 00:38:16 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class SubfleetController
|
|
|
|
* @package App\Http\Controllers\Admin
|
|
|
|
*/
|
|
|
|
class SubfleetController extends Controller
|
2017-06-23 09:55:45 +08:00
|
|
|
{
|
2018-02-28 04:12:03 +08:00
|
|
|
private $aircraftRepo,
|
|
|
|
$fareRepo,
|
|
|
|
$fareSvc,
|
|
|
|
$fleetSvc,
|
2018-03-21 08:17:11 +08:00
|
|
|
$importSvc,
|
2018-02-28 04:12:03 +08:00
|
|
|
$rankRepo,
|
|
|
|
$subfleetRepo;
|
2017-06-23 09:55:45 +08:00
|
|
|
|
2017-11-23 01:52:02 +08:00
|
|
|
/**
|
|
|
|
* SubfleetController constructor.
|
2018-01-10 03:34:19 +08:00
|
|
|
* @param AircraftRepository $aircraftRepo
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param FleetService $fleetSvc
|
|
|
|
* @param FareRepository $fareRepo
|
|
|
|
* @param FareService $fareSvc
|
2018-03-22 08:12:36 +08:00
|
|
|
* @param ImportService $importSvc
|
2018-03-21 08:17:11 +08:00
|
|
|
* @param RankRepository $rankRepo
|
|
|
|
* @param SubfleetRepository $subfleetRepo
|
2017-11-23 01:52:02 +08:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2018-01-10 03:34:19 +08:00
|
|
|
AircraftRepository $aircraftRepo,
|
2018-02-28 04:12:03 +08:00
|
|
|
FleetService $fleetSvc,
|
2018-01-08 00:38:16 +08:00
|
|
|
FareRepository $fareRepo,
|
2018-03-21 08:17:11 +08:00
|
|
|
FareService $fareSvc,
|
2018-03-22 08:12:36 +08:00
|
|
|
ImportService $importSvc,
|
2018-03-21 08:17:11 +08:00
|
|
|
RankRepository $rankRepo,
|
|
|
|
SubfleetRepository $subfleetRepo
|
2017-11-23 01:52:02 +08:00
|
|
|
) {
|
2018-01-10 03:34:19 +08:00
|
|
|
$this->aircraftRepo = $aircraftRepo;
|
2017-11-23 01:52:02 +08:00
|
|
|
$this->fareRepo = $fareRepo;
|
2018-01-08 00:38:16 +08:00
|
|
|
$this->fareSvc = $fareSvc;
|
2018-02-28 04:12:03 +08:00
|
|
|
$this->fleetSvc = $fleetSvc;
|
2018-03-21 08:17:11 +08:00
|
|
|
$this->importSvc = $importSvc;
|
2018-02-28 04:12:03 +08:00
|
|
|
$this->rankRepo = $rankRepo;
|
|
|
|
$this->subfleetRepo = $subfleetRepo;
|
2017-11-23 01:52:02 +08:00
|
|
|
}
|
|
|
|
|
2018-02-21 11:53:50 +08:00
|
|
|
/**
|
|
|
|
* Get the ranks that are available to the subfleet
|
|
|
|
* @param $subfleet
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getAvailRanks($subfleet)
|
|
|
|
{
|
|
|
|
$retval = [];
|
|
|
|
$all_ranks = $this->rankRepo->all();
|
|
|
|
$avail_ranks = $all_ranks->except($subfleet->ranks->modelKeys());
|
|
|
|
foreach ($avail_ranks as $rank) {
|
|
|
|
$retval[$rank->id] = $rank->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
2017-11-23 01:52:02 +08:00
|
|
|
/**
|
|
|
|
* Get all the fares that haven't been assigned to a given subfleet
|
|
|
|
*/
|
2017-06-25 00:09:27 +08:00
|
|
|
protected function getAvailFares($subfleet)
|
|
|
|
{
|
|
|
|
$retval = [];
|
|
|
|
$all_fares = $this->fareRepo->all();
|
|
|
|
$avail_fares = $all_fares->except($subfleet->fares->modelKeys());
|
|
|
|
foreach ($avail_fares as $fare) {
|
|
|
|
$retval[$fare->id] = $fare->name.
|
|
|
|
' (price: '.$fare->price.
|
|
|
|
', cost: '.$fare->cost.
|
|
|
|
', capacity: '.$fare->capacity.')';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
2017-06-23 09:55:45 +08:00
|
|
|
/**
|
|
|
|
* Display a listing of the Subfleet.
|
|
|
|
* @param Request $request
|
|
|
|
* @return Response
|
2018-01-01 04:00:50 +08:00
|
|
|
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
2017-06-23 09:55:45 +08:00
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
|
|
|
$this->subfleetRepo->pushCriteria(new RequestCriteria($request));
|
|
|
|
$subfleets = $this->subfleetRepo->all();
|
|
|
|
|
|
|
|
return view('admin.subfleets.index', [
|
|
|
|
'subfleets' => $subfleets,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new Subfleet.
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
return view('admin.subfleets.create', [
|
2018-03-20 09:50:40 +08:00
|
|
|
'airlines' => Airline::all()->pluck('name', 'id'),
|
2018-01-01 04:00:50 +08:00
|
|
|
'fuel_types' => FuelType::labels(),
|
2017-06-23 09:55:45 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created Subfleet in storage.
|
|
|
|
* @param CreateSubfleetRequest $request
|
|
|
|
* @return Response
|
2018-01-08 00:38:16 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2017-06-23 09:55:45 +08:00
|
|
|
*/
|
|
|
|
public function store(CreateSubfleetRequest $request)
|
|
|
|
{
|
|
|
|
$input = $request->all();
|
|
|
|
$subfleet = $this->subfleetRepo->create($input);
|
|
|
|
|
|
|
|
Flash::success('Subfleet saved successfully.');
|
2018-02-21 11:55:01 +08:00
|
|
|
return redirect(route('admin.subfleets.edit', ['id' => $subfleet->id]));
|
2017-06-23 09:55:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified Subfleet.
|
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
|
|
|
$subfleet = $this->subfleetRepo->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($subfleet)) {
|
|
|
|
Flash::error('Subfleet not found');
|
|
|
|
return redirect(route('admin.subfleets.index'));
|
|
|
|
}
|
|
|
|
|
2017-06-25 00:09:27 +08:00
|
|
|
$avail_fares = $this->getAvailFares($subfleet);
|
|
|
|
return view('admin.subfleets.show', [
|
2018-03-20 09:50:40 +08:00
|
|
|
'subfleet' => $subfleet,
|
2017-06-25 00:09:27 +08:00
|
|
|
'avail_fares' => $avail_fares,
|
|
|
|
]);
|
2017-06-23 09:55:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified Subfleet.
|
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
$subfleet = $this->subfleetRepo->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($subfleet)) {
|
|
|
|
Flash::error('Subfleet not found');
|
|
|
|
return redirect(route('admin.subfleets.index'));
|
|
|
|
}
|
|
|
|
|
2017-07-03 04:11:27 +08:00
|
|
|
$avail_fares = $this->getAvailFares($subfleet);
|
2018-02-21 11:53:50 +08:00
|
|
|
$avail_ranks = $this->getAvailRanks($subfleet);
|
|
|
|
|
2017-06-23 09:55:45 +08:00
|
|
|
return view('admin.subfleets.edit', [
|
2018-03-20 09:50:40 +08:00
|
|
|
'airlines' => Airline::all()->pluck('name', 'id'),
|
|
|
|
'fuel_types' => FuelType::labels(),
|
|
|
|
'avail_fares' => $avail_fares,
|
|
|
|
'avail_ranks' => $avail_ranks,
|
|
|
|
'subfleet' => $subfleet,
|
2017-06-23 09:55:45 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified Subfleet in storage.
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param int $id
|
2017-06-23 09:55:45 +08:00
|
|
|
* @param UpdateSubfleetRequest $request
|
|
|
|
* @return Response
|
2018-01-08 00:38:16 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2017-06-23 09:55:45 +08:00
|
|
|
*/
|
|
|
|
public function update($id, UpdateSubfleetRequest $request)
|
|
|
|
{
|
|
|
|
$subfleet = $this->subfleetRepo->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($subfleet)) {
|
|
|
|
Flash::error('Subfleet not found');
|
|
|
|
return redirect(route('admin.subfleets.index'));
|
|
|
|
}
|
|
|
|
|
2018-01-08 00:38:16 +08:00
|
|
|
$this->subfleetRepo->update($request->all(), $id);
|
2017-06-23 09:55:45 +08:00
|
|
|
|
|
|
|
Flash::success('Subfleet updated successfully.');
|
|
|
|
return redirect(route('admin.subfleets.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified Subfleet from storage.
|
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
$subfleet = $this->subfleetRepo->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($subfleet)) {
|
|
|
|
Flash::error('Subfleet not found');
|
|
|
|
return redirect(route('admin.subfleets.index'));
|
2018-01-10 03:34:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# Make sure no aircraft are assigned to this subfleet
|
|
|
|
# before trying to delete it, or else things might go boom
|
|
|
|
$aircraft = $this->aircraftRepo->findWhere(['subfleet_id' => $id], ['id']);
|
2018-03-20 09:50:40 +08:00
|
|
|
if ($aircraft->count() > 0) {
|
2018-01-10 03:34:19 +08:00
|
|
|
Flash::error('There are aircraft still assigned to this subfleet, you can\'t delete it!')->important();
|
|
|
|
return redirect(route('admin.subfleets.index'));
|
2017-06-23 09:55:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->subfleetRepo->delete($id);
|
|
|
|
|
|
|
|
Flash::success('Subfleet deleted successfully.');
|
|
|
|
return redirect(route('admin.subfleets.index'));
|
|
|
|
}
|
2017-06-25 00:09:27 +08:00
|
|
|
|
2018-03-23 06:59:10 +08:00
|
|
|
/**
|
|
|
|
* Run the subfleet exporter
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
|
|
|
|
*/
|
|
|
|
public function export(Request $request)
|
|
|
|
{
|
|
|
|
$exporter = app(ExportService::class);
|
|
|
|
$subfleets = $this->subfleetRepo->all();
|
|
|
|
|
|
|
|
$path = $exporter->exportSubfleets($subfleets);
|
|
|
|
return response()
|
|
|
|
->download($path, 'subfleets.csv', [
|
|
|
|
'content-type' => 'text/csv',
|
|
|
|
])
|
|
|
|
->deleteFileAfterSend(true);
|
|
|
|
}
|
|
|
|
|
2018-03-21 08:17:11 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
2018-03-23 06:17:37 +08:00
|
|
|
* @throws \Illuminate\Validation\ValidationException
|
2018-03-21 08:17:11 +08:00
|
|
|
*/
|
|
|
|
public function import(Request $request)
|
|
|
|
{
|
|
|
|
$logs = [
|
|
|
|
'success' => [],
|
2018-03-23 06:17:37 +08:00
|
|
|
'errors' => [],
|
2018-03-21 08:17:11 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
if ($request->isMethod('post')) {
|
2018-03-23 06:17:37 +08:00
|
|
|
ImportRequest::validate($request);
|
|
|
|
|
2018-03-21 08:17:11 +08:00
|
|
|
$path = Storage::putFileAs(
|
2018-03-23 06:48:57 +08:00
|
|
|
'import', $request->file('csv_file'), 'import_subfleets.csv'
|
2018-03-21 08:17:11 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
$path = storage_path('app/'.$path);
|
2018-03-23 06:48:57 +08:00
|
|
|
Log::info('Uploaded subfleets import file to '.$path);
|
2018-03-21 08:17:11 +08:00
|
|
|
$logs = $this->importSvc->importSubfleets($path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('admin.subfleets.import', [
|
|
|
|
'logs' => $logs,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-02-21 11:53:50 +08:00
|
|
|
/**
|
|
|
|
* @param Subfleet $subfleet
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
2018-03-06 02:21:38 +08:00
|
|
|
protected function return_ranks_view(?Subfleet $subfleet)
|
2018-02-21 11:53:50 +08:00
|
|
|
{
|
|
|
|
$subfleet->refresh();
|
|
|
|
|
|
|
|
$avail_ranks = $this->getAvailRanks($subfleet);
|
|
|
|
return view('admin.subfleets.ranks', [
|
2018-03-20 09:50:40 +08:00
|
|
|
'subfleet' => $subfleet,
|
2018-02-21 11:53:50 +08:00
|
|
|
'avail_ranks' => $avail_ranks,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-01-08 00:38:16 +08:00
|
|
|
/**
|
|
|
|
* @param Subfleet $subfleet
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
2018-03-06 02:21:38 +08:00
|
|
|
protected function return_fares_view(?Subfleet $subfleet)
|
2017-06-25 00:09:27 +08:00
|
|
|
{
|
|
|
|
$subfleet->refresh();
|
2018-02-21 11:53:50 +08:00
|
|
|
|
2017-06-25 00:09:27 +08:00
|
|
|
$avail_fares = $this->getAvailFares($subfleet);
|
|
|
|
return view('admin.subfleets.fares', [
|
|
|
|
'subfleet' => $subfleet,
|
|
|
|
'avail_fares' => $avail_fares,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-21 11:53:50 +08:00
|
|
|
* Operations for associating ranks to the subfleet
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param $id
|
2017-06-25 00:09:27 +08:00
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
2018-02-21 11:53:50 +08:00
|
|
|
public function ranks($id, Request $request)
|
2017-06-25 00:09:27 +08:00
|
|
|
{
|
2018-02-21 11:53:50 +08:00
|
|
|
$subfleet = $this->subfleetRepo->findWithoutFail($id);
|
|
|
|
if (empty($subfleet)) {
|
|
|
|
return $this->return_ranks_view($subfleet);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->isMethod('get')) {
|
|
|
|
return $this->return_ranks_view($subfleet);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* update specific rank data
|
|
|
|
*/
|
|
|
|
if ($request->isMethod('post')) {
|
2018-03-10 03:03:43 +08:00
|
|
|
$rank = $this->rankRepo->find($request->input('rank_id'));
|
2018-02-28 04:12:03 +08:00
|
|
|
$this->fleetSvc->addSubfleetToRank($subfleet, $rank);
|
2018-03-20 09:50:40 +08:00
|
|
|
} elseif ($request->isMethod('put')) {
|
2018-02-27 09:14:10 +08:00
|
|
|
$override = [];
|
2018-03-10 03:03:43 +08:00
|
|
|
$rank = $this->rankRepo->find($request->input('rank_id'));
|
2018-02-27 09:14:10 +08:00
|
|
|
$override[$request->name] = $request->value;
|
2018-02-28 04:12:03 +08:00
|
|
|
|
|
|
|
$this->fleetSvc->addSubfleetToRank($subfleet, $rank, $override);
|
2018-03-20 09:50:40 +08:00
|
|
|
} // dissassociate fare from teh aircraft
|
2018-02-21 11:53:50 +08:00
|
|
|
elseif ($request->isMethod('delete')) {
|
2018-03-10 03:03:43 +08:00
|
|
|
$rank = $this->rankRepo->find($request->input('rank_id'));
|
2018-02-28 04:12:03 +08:00
|
|
|
$this->fleetSvc->removeSubfleetFromRank($subfleet, $rank);
|
2018-02-21 11:53:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$subfleet->save();
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-02-21 11:53:50 +08:00
|
|
|
return $this->return_ranks_view($subfleet);
|
|
|
|
}
|
|
|
|
|
2018-03-06 02:21:38 +08:00
|
|
|
/**
|
|
|
|
* @param Subfleet $subfleet
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
|
|
|
protected function return_expenses_view(?Subfleet $subfleet)
|
|
|
|
{
|
|
|
|
$subfleet->refresh();
|
|
|
|
return view('admin.subfleets.expenses', [
|
|
|
|
'subfleet' => $subfleet,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Operations for associating ranks to the subfleet
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param $id
|
2018-03-06 02:21:38 +08:00
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function expenses($id, Request $request)
|
|
|
|
{
|
|
|
|
$subfleet = $this->subfleetRepo->findWithoutFail($id);
|
|
|
|
if (empty($subfleet)) {
|
|
|
|
return $this->return_expenses_view($subfleet);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->isMethod('get')) {
|
|
|
|
return $this->return_expenses_view($subfleet);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* update specific rank data
|
|
|
|
*/
|
|
|
|
if ($request->isMethod('post')) {
|
2018-03-06 11:24:49 +08:00
|
|
|
$expense = new Expense($request->post());
|
2018-04-02 03:32:01 +08:00
|
|
|
$expense->ref_model = Subfleet::class;
|
|
|
|
$expense->ref_model_id = $subfleet->id;
|
2018-03-06 02:21:38 +08:00
|
|
|
$expense->save();
|
|
|
|
} elseif ($request->isMethod('put')) {
|
2018-03-06 11:24:49 +08:00
|
|
|
$expense = Expense::findOrFail($request->input('expense_id'));
|
2018-03-06 02:21:38 +08:00
|
|
|
$expense->{$request->name} = $request->value;
|
|
|
|
$expense->save();
|
|
|
|
} // dissassociate fare from teh aircraft
|
|
|
|
elseif ($request->isMethod('delete')) {
|
2018-03-06 11:24:49 +08:00
|
|
|
$expense = Expense::findOrFail($request->input('expense_id'));
|
2018-03-06 02:21:38 +08:00
|
|
|
$expense->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->return_expenses_view($subfleet);
|
|
|
|
}
|
|
|
|
|
2018-02-21 11:53:50 +08:00
|
|
|
/**
|
|
|
|
* Operations on fares to the subfleet
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param $id
|
2018-02-21 11:53:50 +08:00
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function fares($id, Request $request)
|
|
|
|
{
|
2017-06-25 00:09:27 +08:00
|
|
|
$subfleet = $this->subfleetRepo->findWithoutFail($id);
|
|
|
|
if (empty($subfleet)) {
|
2017-11-23 01:52:02 +08:00
|
|
|
return $this->return_fares_view($subfleet);
|
2017-06-25 00:09:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->isMethod('get')) {
|
|
|
|
return $this->return_fares_view($subfleet);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* update specific fare data
|
|
|
|
*/
|
|
|
|
if ($request->isMethod('post')) {
|
2018-02-27 09:14:10 +08:00
|
|
|
$fare = $this->fareRepo->find($request->fare_id);
|
2018-01-08 00:38:16 +08:00
|
|
|
$this->fareSvc->setForSubfleet($subfleet, $fare);
|
2018-03-20 09:50:40 +08:00
|
|
|
} // update the pivot table with overrides for the fares
|
2017-06-25 00:09:27 +08:00
|
|
|
elseif ($request->isMethod('put')) {
|
|
|
|
$override = [];
|
2018-02-27 09:14:10 +08:00
|
|
|
$fare = $this->fareRepo->find($request->fare_id);
|
2017-06-25 00:09:27 +08:00
|
|
|
$override[$request->name] = $request->value;
|
2018-01-08 00:38:16 +08:00
|
|
|
$this->fareSvc->setForSubfleet($subfleet, $fare, $override);
|
2018-03-20 09:50:40 +08:00
|
|
|
} // dissassociate fare from teh aircraft
|
2017-06-25 00:09:27 +08:00
|
|
|
elseif ($request->isMethod('delete')) {
|
2018-02-27 09:14:10 +08:00
|
|
|
$fare = $this->fareRepo->find($request->fare_id);
|
2018-01-08 00:38:16 +08:00
|
|
|
$this->fareSvc->delFareFromSubfleet($subfleet, $fare);
|
2017-06-25 00:09:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->return_fares_view($subfleet);
|
|
|
|
}
|
2017-06-23 09:55:45 +08:00
|
|
|
}
|