diff --git a/app/Database/migrations/2018_02_26_185121_create_expenses_table.php b/app/Database/migrations/2018_02_26_185121_create_expenses_table.php new file mode 100644 index 00000000..1dcb81ed --- /dev/null +++ b/app/Database/migrations/2018_02_26_185121_create_expenses_table.php @@ -0,0 +1,37 @@ +increments('id'); + $table->unsignedInteger('airline_id')->nullable(); + $table->string('name'); + $table->unsignedDecimal('amount'); + $table->unsignedTinyInteger('type'); + $table->boolean('multiplier')->nullable()->default(0); + $table->boolean('active')->nullable()->default(1); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('expenses'); + } +} diff --git a/app/Database/seeds/sample.yml b/app/Database/seeds/sample.yml index 6489a8c2..fd70497f 100644 --- a/app/Database/seeds/sample.yml +++ b/app/Database/seeds/sample.yml @@ -173,6 +173,31 @@ aircraft: registration: status: 2 +expenses: + - name: Per-Flight (no muliplier) + amount: 100 + type: 0 + active: 1 + - name: Per-Flight (multiplier) + amount: 100 + type: 0 + multiplier: 1 + active: 1 + - name: Per-Flight (multiplier, on airline) + airline_id: 1 + amount: 200 + type: 0 + multiplier: 1 + active: 1 + - name: A daily fee + amount: 800 + type: 1 + active: 1 + - name: A monthly fee + amount: 5000 + type: 2 + active: 1 + fares: - id: 1 code: Y diff --git a/app/Events/Expenses.php b/app/Events/Expenses.php new file mode 100644 index 00000000..4f06d218 --- /dev/null +++ b/app/Events/Expenses.php @@ -0,0 +1,45 @@ +pirep = $pirep; + } +} diff --git a/app/Http/Controllers/Admin/ExpenseController.php b/app/Http/Controllers/Admin/ExpenseController.php new file mode 100644 index 00000000..bb9c2417 --- /dev/null +++ b/app/Http/Controllers/Admin/ExpenseController.php @@ -0,0 +1,156 @@ +airlineRepo = $airlineRepo; + $this->expenseRepo = $expenseRepo; + } + + /** + * Display a listing of the expenses. + * @param Request $request + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @throws \Prettus\Repository\Exceptions\RepositoryException + */ + public function index(Request $request) + { + $this->expenseRepo->pushCriteria(new RequestCriteria($request)); + $expenses = $this->expenseRepo->all(); + + return view('admin.expenses.index', [ + 'expenses' => $expenses + ]); + } + + /** + * Show the form for creating a new expenses. + */ + public function create() + { + return view('admin.expenses.create', [ + 'airlines_list' => $this->airlineRepo->selectBoxList(true), + 'expense_types' => ExpenseType::select(), + ]); + } + + /** + * Store a newly created expenses in storage. + * @param Request $request + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @throws \Prettus\Validator\Exceptions\ValidatorException + */ + public function store(Request $request) + { + $input = $request->all(); + $this->expenseRepo->create($input); + + Flash::success('Expense saved successfully.'); + return redirect(route('admin.expenses.index')); + } + + /** + * Display the specified expenses. + * @param int $id + * @return mixed + */ + public function show($id) + { + $expenses = $this->expenseRepo->findWithoutFail($id); + + if (empty($expenses)) { + Flash::error('expenses not found'); + return redirect(route('admin.expenses.index')); + } + + return view('admin.expenses.show', [ + 'expenses' => $expenses, + ]); + } + + /** + * Show the form for editing the specified expenses. + * @param int $id + * @return Response + */ + public function edit($id) + { + $expense = $this->expenseRepo->findWithoutFail($id); + + if (empty($expense)) { + Flash::error('Expense not found'); + return redirect(route('admin.expenses.index')); + } + + return view('admin.expenses.edit', [ + 'expense' => $expense, + 'airlines_list' => $this->airlineRepo->selectBoxList(true), + 'expense_types' => ExpenseType::select(), + ]); + } + + /** + * Update the specified expenses in storage. + * @param int $id + * @param Request $request + * @return Response + * @throws \Prettus\Validator\Exceptions\ValidatorException + */ + public function update($id, Request $request) + { + $expenses = $this->expenseRepo->findWithoutFail($id); + + if (empty($expenses)) { + Flash::error('Expense not found'); + return redirect(route('admin.expenses.index')); + } + + $this->expenseRepo->update($request->all(), $id); + + Flash::success('Expense updated successfully.'); + return redirect(route('admin.expenses.index')); + } + + /** + * Remove the specified expenses from storage. + * @param int $id + * @return Response + */ + public function destroy($id) + { + $expenses = $this->expenseRepo->findWithoutFail($id); + + if (empty($expenses)) { + Flash::error('Expense not found'); + return redirect(route('admin.expenses.index')); + } + + $this->expenseRepo->delete($id); + + Flash::success('Expense deleted successfully.'); + return redirect(route('admin.expenses.index')); + } +} diff --git a/app/Models/Enums/GenericState.php b/app/Models/Enums/ActiveState.php similarity index 53% rename from app/Models/Enums/GenericState.php rename to app/Models/Enums/ActiveState.php index 0d97daa8..861a25b2 100644 --- a/app/Models/Enums/GenericState.php +++ b/app/Models/Enums/ActiveState.php @@ -3,16 +3,16 @@ namespace App\Models\Enums; /** - * Class GenericState + * Class ActiveState * @package App\Models\Enums */ -class GenericState extends EnumBase +class ActiveState extends EnumBase { public const INACTIVE = 0; public const ACTIVE = 1; public static $labels = [ - GenericState::INACTIVE => 'Inactive', - GenericState::ACTIVE => 'Active', + ActiveState::INACTIVE => 'Inactive', + ActiveState::ACTIVE => 'Active', ]; } diff --git a/app/Models/Enums/ExpenseType.php b/app/Models/Enums/ExpenseType.php new file mode 100644 index 00000000..a3c07195 --- /dev/null +++ b/app/Models/Enums/ExpenseType.php @@ -0,0 +1,20 @@ + 'Flight', + ExpenseType::DAILY => 'Daily', + ExpenseType::MONTHLY => 'Monthly', + ]; +} diff --git a/app/Models/Expense.php b/app/Models/Expense.php new file mode 100644 index 00000000..4ae4e802 --- /dev/null +++ b/app/Models/Expense.php @@ -0,0 +1,38 @@ + 'boolean', + 'airline_id' => 'integer', + 'amount' => 'float', + 'multiplier' => 'integer', + 'type' => 'integer', + ]; + + /** + * Foreign Keys + */ + + public function airline() + { + return $this->belongsTo(Airline::class, 'airline_id'); + } +} diff --git a/app/Repositories/ExpenseRepository.php b/app/Repositories/ExpenseRepository.php new file mode 100644 index 00000000..37a94dd4 --- /dev/null +++ b/app/Repositories/ExpenseRepository.php @@ -0,0 +1,21 @@ +name('settings.update'); - # pirep related routes Route::get('pireps/fares', 'PirepController@fares'); Route::get('pireps/pending', 'PirepController@pending'); @@ -45,6 +36,19 @@ Route::group([ Route::resource('pirepfields', 'PirepFieldController'); + # rankings + Route::resource('ranks', 'RankController'); + Route::match(['get', 'post', 'put', 'delete'], 'ranks/{id}/subfleets', 'RankController@subfleets'); + + # settings + Route::match(['get'], 'settings', 'SettingsController@index'); + Route::match(['post', 'put'], 'settings', 'SettingsController@update')->name('settings.update'); + + # subfleet + Route::resource('subfleets', 'SubfleetController'); + Route::match(['get', 'post', 'put', 'delete'], 'subfleets/{id}/fares', 'SubfleetController@fares'); + Route::match(['get', 'post', 'delete'], 'subfleets/{id}/ranks', 'SubfleetController@ranks'); + Route::resource('users', 'UserController'); Route::get('users/{id}/regen_apikey', 'UserController@regen_apikey')->name('users.regen_apikey'); diff --git a/config/app.php b/config/app.php index 829a271f..429ac6fc 100755 --- a/config/app.php +++ b/config/app.php @@ -127,7 +127,7 @@ return [ 'Yaml' => Symfony\Component\Yaml\Yaml::class, # ENUMS - 'GenericState' => App\Models\Enums\GenericState::class, + 'ActiveState' => App\Models\Enums\ActiveState::class, 'UserState' => App\Models\Enums\UserState::class, 'PirepSource' => App\Models\Enums\PirepSource::class, 'PirepState' => App\Models\Enums\PirepState::class, diff --git a/resources/views/admin/aircraft/index.blade.php b/resources/views/admin/aircraft/index.blade.php index c7c5296b..7473604f 100644 --- a/resources/views/admin/aircraft/index.blade.php +++ b/resources/views/admin/aircraft/index.blade.php @@ -15,8 +15,10 @@ @endsection @section('content') -
{{ $errors->first('ground_handling_cost') }}
@component('admin.components.info') This is the base rate per-flight. A multiplier for this rate can be set in the subfleet, so you can modulate those costs from there. @endcomponent - - {!! Form::number('ground_handling_cost', null, ['class' => 'form-control']) !!} -{{ $errors->first('ground_handling_cost') }}
{{ $errors->first('airline_id') }}
+ @component('admin.components.info') + If an airline is selected, then the expense will only be applied + to the selected airline, or flights in that airline. + @endcomponent +{{ $errors->first('type') }}
+{{ $errors->first('name') }}
+{{ $errors->first('amount') }}
++ You must add a subfleet before you can add an aircraft! +
+ @else + @include('admin.expenses.table') + @endif +Name | +Type | +Amount | +Airline | +Active | ++ + + @foreach($expenses as $expense) + |
---|---|---|---|---|---|
+ {!! $expense->name !!} + | +{!! \App\Models\Enums\ExpenseType::label($expense->type) !!} | +{!! $expense->amount !!} | ++ @if(filled($expense->airline)) + {!! $expense->airline->name !!} + @else + - + @endif + | ++ + {!! \App\Models\Enums\ActiveState::label($expense->active) !!} + + | ++ {!! Form::open(['route' => ['admin.expenses.destroy', $expense->id], 'method' => 'delete']) !!} + + {!! Form::button('', ['type' => 'submit', 'class' => 'btn btn-sm btn-danger btn-icon', 'onclick' => "return confirm('Are you sure?')"]) !!} + {!! Form::close() !!} + | +
{!! $setting->name !!}
-{{$setting->description}}
+ @component('admin.components.info') + {{$setting->description}} + @endcomponent +
{{ $errors->first('ground_handling_multiplier') }}
@component('admin.components.info') This is the multiplier of the airport ground-handling cost to charge for aircraft in this subfleet, as a percentage. Defaults to 100. @endcomponent - - {!! Form::text('ground_handling_multiplier', null, ['class' => 'form-control']) !!} -{{ $errors->first('ground_handling_multiplier') }}