From 4a73a5a6b33ac3e51c185f6b0a53d8f6ce544101 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Mon, 26 Feb 2018 15:16:12 -0600 Subject: [PATCH] Add table/models and admin for expenses #136 --- ...018_02_26_185121_create_expenses_table.php | 37 +++++ app/Database/seeds/sample.yml | 25 +++ app/Events/Expenses.php | 45 +++++ .../Controllers/Admin/ExpenseController.php | 156 ++++++++++++++++++ .../{GenericState.php => ActiveState.php} | 8 +- app/Models/Enums/ExpenseType.php | 20 +++ app/Models/Expense.php | 38 +++++ app/Repositories/ExpenseRepository.php | 21 +++ app/Routes/admin.php | 34 ++-- config/app.php | 2 +- .../views/admin/aircraft/index.blade.php | 6 +- .../views/admin/airlines/index.blade.php | 4 +- .../views/admin/airports/fields.blade.php | 5 +- .../views/admin/airports/index.blade.php | 4 +- .../views/admin/expenses/create.blade.php | 11 ++ resources/views/admin/expenses/edit.blade.php | 11 ++ .../views/admin/expenses/fields.blade.php | 64 +++++++ .../views/admin/expenses/index.blade.php | 25 +++ .../views/admin/expenses/table.blade.php | 40 +++++ resources/views/admin/fares/index.blade.php | 6 +- .../views/admin/flights/fields.blade.php | 1 + resources/views/admin/flights/index.blade.php | 6 +- resources/views/admin/menu.blade.php | 5 +- resources/views/admin/ranks/index.blade.php | 6 +- .../views/admin/settings/table.blade.php | 6 +- .../views/admin/subfleets/fields.blade.php | 5 +- resources/views/admin/users/index.blade.php | 6 +- 27 files changed, 556 insertions(+), 41 deletions(-) create mode 100644 app/Database/migrations/2018_02_26_185121_create_expenses_table.php create mode 100644 app/Events/Expenses.php create mode 100644 app/Http/Controllers/Admin/ExpenseController.php rename app/Models/Enums/{GenericState.php => ActiveState.php} (53%) create mode 100644 app/Models/Enums/ExpenseType.php create mode 100644 app/Models/Expense.php create mode 100644 app/Repositories/ExpenseRepository.php create mode 100644 resources/views/admin/expenses/create.blade.php create mode 100644 resources/views/admin/expenses/edit.blade.php create mode 100644 resources/views/admin/expenses/fields.blade.php create mode 100644 resources/views/admin/expenses/index.blade.php create mode 100644 resources/views/admin/expenses/table.blade.php 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') -
- @include('admin.aircraft.table') +
+
+ @include('admin.aircraft.table') +
@endsection diff --git a/resources/views/admin/airlines/index.blade.php b/resources/views/admin/airlines/index.blade.php index 7dc076c0..5a921ed4 100644 --- a/resources/views/admin/airlines/index.blade.php +++ b/resources/views/admin/airlines/index.blade.php @@ -10,8 +10,10 @@ @endsection @section('content') -
+
+
@include('admin.airlines.table') +
@endsection diff --git a/resources/views/admin/airports/fields.blade.php b/resources/views/admin/airports/fields.blade.php index 09f9db52..5ec2a7d9 100644 --- a/resources/views/admin/airports/fields.blade.php +++ b/resources/views/admin/airports/fields.blade.php @@ -62,14 +62,13 @@
{!! Form::label('ground_handling_cost', 'Ground Handling Cost:') !!} + {!! Form::number('ground_handling_cost', null, ['class' => 'form-control']) !!} +

{{ $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') }}

diff --git a/resources/views/admin/airports/index.blade.php b/resources/views/admin/airports/index.blade.php index 3573602d..bd0adf18 100644 --- a/resources/views/admin/airports/index.blade.php +++ b/resources/views/admin/airports/index.blade.php @@ -14,8 +14,10 @@ @include('admin.airports.search')
-
+
+
@include('admin.airports.table') +
diff --git a/resources/views/admin/expenses/create.blade.php b/resources/views/admin/expenses/create.blade.php new file mode 100644 index 00000000..23fd9c81 --- /dev/null +++ b/resources/views/admin/expenses/create.blade.php @@ -0,0 +1,11 @@ +@extends('admin.app') +@section('title', 'Add Expense') +@section('content') +
+
+ {!! Form::open(['route' => 'admin.expenses.store']) !!} + @include('admin.expenses.fields') + {!! Form::close() !!} +
+
+@endsection diff --git a/resources/views/admin/expenses/edit.blade.php b/resources/views/admin/expenses/edit.blade.php new file mode 100644 index 00000000..a59d46c6 --- /dev/null +++ b/resources/views/admin/expenses/edit.blade.php @@ -0,0 +1,11 @@ +@extends('admin.app') +@section('title', "Edit \"$expense->name\"") +@section('content') +
+
+ {!! Form::model($expense, ['route' => ['admin.expenses.update', $expense->id], 'method' => 'patch']) !!} + @include('admin.expenses.fields') + {!! Form::close() !!} +
+
+@endsection diff --git a/resources/views/admin/expenses/fields.blade.php b/resources/views/admin/expenses/fields.blade.php new file mode 100644 index 00000000..b2ee6724 --- /dev/null +++ b/resources/views/admin/expenses/fields.blade.php @@ -0,0 +1,64 @@ +
+ +
+ {!! Form::label('airline_id', 'Airline:') !!} + + {!! Form::select('airline_id', $airlines_list, null , ['class' => 'form-control select2']) !!} +

{{ $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 +
+ + +
+ {!! Form::label('type', 'Expense Type:') !!} * + {!! Form::select('type', $expense_types, null , ['class' => 'form-control select2']) !!} +

{{ $errors->first('type') }}

+
+
+
+
+ {!! Form::label('name', 'Expense Name:') !!} + {!! Form::text('name', null, ['class' => 'form-control']) !!} +

{{ $errors->first('name') }}

+
+ +
+ {!! Form::label('amount', 'Amount:') !!} + {!! Form::number('amount', null, ['class' => 'form-control', 'min' => 0]) !!} +

{{ $errors->first('amount') }}

+
+ +
+ +
+ +
+ {!! Form::label('multiplier', 'Multiplier:') !!} + + @component('admin.components.info') + If checked, with a PIREP, this expense can be modified by a multiplier + on the subfleet. This is ignored for daily and monthly expenses + @endcomponent +
+ +
+ {!! Form::label('active', 'Active:') !!} + +
+ +
+
+ {!! Form::button('Save', ['type' => 'submit', 'class' => 'btn btn-success']) !!} + Cancel +
+
+
diff --git a/resources/views/admin/expenses/index.blade.php b/resources/views/admin/expenses/index.blade.php new file mode 100644 index 00000000..b595d02c --- /dev/null +++ b/resources/views/admin/expenses/index.blade.php @@ -0,0 +1,25 @@ +@extends('admin.app') + +@section('title', 'Expenses') +@section('actions') +
  • + + + Add New +
  • +@endsection + +@section('content') +
    +
    + @if(!filled($expenses)) +

    + You must add a subfleet before you can add an aircraft! +

    + @else + @include('admin.expenses.table') + @endif +
    +
    +@endsection + diff --git a/resources/views/admin/expenses/table.blade.php b/resources/views/admin/expenses/table.blade.php new file mode 100644 index 00000000..8aa3e82d --- /dev/null +++ b/resources/views/admin/expenses/table.blade.php @@ -0,0 +1,40 @@ + + + + + + + + + + + @foreach($expenses as $expense) + + + + + + + + + @endforeach + +
    NameTypeAmountAirlineActive
    + {!! $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() !!} +
    diff --git a/resources/views/admin/fares/index.blade.php b/resources/views/admin/fares/index.blade.php index 388e3358..867e1303 100644 --- a/resources/views/admin/fares/index.blade.php +++ b/resources/views/admin/fares/index.blade.php @@ -11,8 +11,10 @@ @endsection @section('content') -
    - @include('admin.fares.table') +
    +
    + @include('admin.fares.table') +
    @endsection diff --git a/resources/views/admin/flights/fields.blade.php b/resources/views/admin/flights/fields.blade.php index 943e657a..a193466f 100644 --- a/resources/views/admin/flights/fields.blade.php +++ b/resources/views/admin/flights/fields.blade.php @@ -117,6 +117,7 @@
    {!! Form::label('active', 'Active:') !!} + {!! Form::hidden('active', 0, false) !!} @if($flight!==null) {!! Form::checkbox('active', $flight->active, ['class' => 'form-control icheck']) !!} @else diff --git a/resources/views/admin/flights/index.blade.php b/resources/views/admin/flights/index.blade.php index 9f388cb7..b8e3d5c1 100644 --- a/resources/views/admin/flights/index.blade.php +++ b/resources/views/admin/flights/index.blade.php @@ -14,8 +14,10 @@ @include('admin.flights.search')
    -
    - @include('admin.flights.table') +
    +
    + @include('admin.flights.table') +
    diff --git a/resources/views/admin/menu.blade.php b/resources/views/admin/menu.blade.php index 3d334eb8..d057e906 100644 --- a/resources/views/admin/menu.blade.php +++ b/resources/views/admin/menu.blade.php @@ -33,9 +33,10 @@ class="pe-7s-paper-plane">airlines
  • airports
  • +
  • expenses
  • users
  • -
  • ranks
  • -
  • settings
  • +
  • ranks
  • +
  • settings
  • diff --git a/resources/views/admin/ranks/index.blade.php b/resources/views/admin/ranks/index.blade.php index 4fe69623..5e5ec3a7 100644 --- a/resources/views/admin/ranks/index.blade.php +++ b/resources/views/admin/ranks/index.blade.php @@ -9,8 +9,10 @@ @endsection @section('content') -
    - @include('admin.ranks.table') +
    +
    + @include('admin.ranks.table') +
    @endsection @include('admin.ranks.scripts') diff --git a/resources/views/admin/settings/table.blade.php b/resources/views/admin/settings/table.blade.php index 02258587..b5bf5a0d 100644 --- a/resources/views/admin/settings/table.blade.php +++ b/resources/views/admin/settings/table.blade.php @@ -13,7 +13,11 @@

    {!! $setting->name !!}

    -

    {{$setting->description}}

    +

    + @component('admin.components.info') + {{$setting->description}} + @endcomponent +

    @if($setting->type === 'date') {!! Form::input('text', $setting->id, $setting->value, ['class' => 'form-control', 'id' => 'datepicker']) !!} diff --git a/resources/views/admin/subfleets/fields.blade.php b/resources/views/admin/subfleets/fields.blade.php index 1e861415..a4c5d83a 100644 --- a/resources/views/admin/subfleets/fields.blade.php +++ b/resources/views/admin/subfleets/fields.blade.php @@ -28,14 +28,13 @@
    {!! Form::label('ground_handling_multiplier', 'Ground Handling Multiplier:') !!} + {!! Form::text('ground_handling_multiplier', null, ['class' => 'form-control']) !!} +

    {{ $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') }}

    diff --git a/resources/views/admin/users/index.blade.php b/resources/views/admin/users/index.blade.php index 87f3c0cf..a822a85b 100644 --- a/resources/views/admin/users/index.blade.php +++ b/resources/views/admin/users/index.blade.php @@ -12,8 +12,10 @@ @include('admin.users.search')
    -
    - @include('admin.users.table') +
    +
    + @include('admin.users.table') +