From 632c5782def6d271a5cbb0ac33276ed3378ade6c Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Fri, 6 Mar 2020 15:10:03 -0500 Subject: [PATCH] Add fare type for pax/cargo/mixed flights #621 (#623) --- .../2020_03_06_141153_fares_add_type.php | 34 +++++++++++ app/Http/Controllers/Admin/FareController.php | 14 ++++- .../Controllers/Admin/SubfleetController.php | 10 +++- app/Http/Resources/Fare.php | 1 + app/Models/Enums/FareType.php | 16 ++++++ app/Models/Expense.php | 5 ++ app/Models/Fare.php | 3 + app/Services/Finance/PirepFinanceService.php | 7 ++- resources/views/admin/fares/fields.blade.php | 36 +++++++++--- .../views/admin/subfleets/fares.blade.php | 12 ++-- .../views/admin/subfleets/fields.blade.php | 56 ++++++++++--------- .../layouts/default/pireps/fares.blade.php | 2 +- 12 files changed, 150 insertions(+), 46 deletions(-) create mode 100644 app/Database/migrations/2020_03_06_141153_fares_add_type.php create mode 100644 app/Models/Enums/FareType.php diff --git a/app/Database/migrations/2020_03_06_141153_fares_add_type.php b/app/Database/migrations/2020_03_06_141153_fares_add_type.php new file mode 100644 index 00000000..bd0d8c5c --- /dev/null +++ b/app/Database/migrations/2020_03_06_141153_fares_add_type.php @@ -0,0 +1,34 @@ +unsignedTinyInteger('type') + ->default(FareType::PASSENGER) + ->nullable() + ->after('capacity'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('fares', function (Blueprint $table) { + $table->dropColumn('type'); + }); + } +} diff --git a/app/Http/Controllers/Admin/FareController.php b/app/Http/Controllers/Admin/FareController.php index a12934d0..82941fdd 100644 --- a/app/Http/Controllers/Admin/FareController.php +++ b/app/Http/Controllers/Admin/FareController.php @@ -6,6 +6,7 @@ use App\Contracts\Controller; use App\Http\Controllers\Admin\Traits\Importable; use App\Http\Requests\CreateFareRequest; use App\Http\Requests\UpdateFareRequest; +use App\Models\Enums\FareType; use App\Models\Enums\ImportExportType; use App\Repositories\FareRepository; use App\Services\ExportService; @@ -58,7 +59,9 @@ class FareController extends Controller */ public function create() { - return view('admin.fares.create'); + return view('admin.fares.create', [ + 'fare_types' => FareType::select(), + ]); } /** @@ -94,7 +97,9 @@ class FareController extends Controller return redirect(route('admin.fares.index')); } - return view('admin.fares.show')->with('fare', $fare); + return view('admin.fares.show', [ + 'fare' => $fare, + ]); } /** @@ -112,7 +117,10 @@ class FareController extends Controller return redirect(route('admin.fares.index')); } - return view('admin.fares.edit')->with('fare', $fare); + return view('admin.fares.edit', [ + 'fare' => $fare, + 'fare_types' => FareType::select(), + ]); } /** diff --git a/app/Http/Controllers/Admin/SubfleetController.php b/app/Http/Controllers/Admin/SubfleetController.php index ba85390c..7943ee11 100644 --- a/app/Http/Controllers/Admin/SubfleetController.php +++ b/app/Http/Controllers/Admin/SubfleetController.php @@ -7,6 +7,7 @@ use App\Http\Controllers\Admin\Traits\Importable; use App\Http\Requests\CreateSubfleetRequest; use App\Http\Requests\UpdateSubfleetRequest; use App\Models\Airline; +use App\Models\Enums\FareType; use App\Models\Enums\FuelType; use App\Models\Enums\ImportExportType; use App\Models\Expense; @@ -98,6 +99,7 @@ class SubfleetController extends Controller foreach ($avail_fares as $fare) { $retval[$fare->id] = $fare->name. ' (price: '.$fare->price. + ', type: '.FareType::label($fare->type). ', cost: '.$fare->cost. ', capacity: '.$fare->capacity.')'; } @@ -162,7 +164,9 @@ class SubfleetController extends Controller */ public function show($id) { - $subfleet = $this->subfleetRepo->findWithoutFail($id); + $subfleet = $this->subfleetRepo + ->with(['fares']) + ->findWithoutFail($id); if (empty($subfleet)) { Flash::error('Subfleet not found'); @@ -185,7 +189,9 @@ class SubfleetController extends Controller */ public function edit($id) { - $subfleet = $this->subfleetRepo->findWithoutFail($id); + $subfleet = $this->subfleetRepo + ->with(['fares', 'ranks']) + ->findWithoutFail($id); if (empty($subfleet)) { Flash::error('Subfleet not found'); diff --git a/app/Http/Resources/Fare.php b/app/Http/Resources/Fare.php index 996c3eec..50c90b49 100644 --- a/app/Http/Resources/Fare.php +++ b/app/Http/Resources/Fare.php @@ -18,6 +18,7 @@ class Fare extends Resource 'price' => $this->price, 'cost' => $this->cost, 'capacity' => $this->capacity, + 'type' => $this->type, 'notes' => $this->notes, 'active' => $this->active, ]; diff --git a/app/Models/Enums/FareType.php b/app/Models/Enums/FareType.php new file mode 100644 index 00000000..f18be6b1 --- /dev/null +++ b/app/Models/Enums/FareType.php @@ -0,0 +1,16 @@ + 'Passenger', + self::CARGO => 'Cargo', + ]; +} diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 3a328487..cf36f46f 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -78,4 +78,9 @@ class Expense extends Model { return $this->belongsTo(Airline::class, 'airline_id'); } + + public function ref_model() + { + return $this->morphTo(); + } } diff --git a/app/Models/Fare.php b/app/Models/Fare.php index b0ec45b6..0ceffb6a 100644 --- a/app/Models/Fare.php +++ b/app/Models/Fare.php @@ -11,6 +11,7 @@ use App\Contracts\Model; * @property int code * @property int capacity * @property int count Only when merged with pivot + * @property int type * @property string notes * @property bool active */ @@ -32,12 +33,14 @@ class Fare extends Model 'price' => 'float', 'cost' => 'float', 'capacity' => 'integer', + 'type' => 'integer', 'active' => 'boolean', ]; public static $rules = [ 'code' => 'required', 'name' => 'required', + 'type' => 'required', ]; /** diff --git a/app/Services/Finance/PirepFinanceService.php b/app/Services/Finance/PirepFinanceService.php index d8e6f99c..c2412599 100644 --- a/app/Services/Finance/PirepFinanceService.php +++ b/app/Services/Finance/PirepFinanceService.php @@ -7,6 +7,7 @@ use App\Events\Expenses as ExpensesEvent; use App\Models\Aircraft; use App\Models\Airport; use App\Models\Enums\ExpenseType; +use App\Models\Enums\FareType; use App\Models\Enums\PirepSource; use App\Models\Expense; use App\Models\Pirep; @@ -124,13 +125,15 @@ class PirepFinanceService extends Service Log::info('Finance: Calculate: C='.$credit->toAmount().', D='.$debit->toAmount()); + $memo = FareType::label($fare->type).' fare: '.$fare->code.$fare->count + .'; price: '.$fare->price.', cost: '.$fare->cost; + $this->journalRepo->post( $pirep->airline->journal, $credit, $debit, $pirep, - 'Fares '.$fare->code.$fare->count - .'; price: '.$fare->price.', cost: '.$fare->cost, + $memo, null, 'Fares', 'fare' diff --git a/resources/views/admin/fares/fields.blade.php b/resources/views/admin/fares/fields.blade.php index 3fa6ab5c..dacfaea9 100644 --- a/resources/views/admin/fares/fields.blade.php +++ b/resources/views/admin/fares/fields.blade.php @@ -9,7 +9,7 @@
-
+
{{ Form::label('code', 'Code:') }} * @component('admin.components.info') How this fare class will show up on a ticket @@ -18,7 +18,7 @@

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

-
+
{{ Form::label('name', 'Name:') }} * @component('admin.components.info') The fare class name, E.g, "Economy" or "First" @@ -27,10 +27,25 @@

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

+
+ {{ Form::label('type', 'Fare Type:') }} * + @component('admin.components.info') + If this is a passenger or cargo fare + @endcomponent + {{ Form::select('type', $fare_types, null , [ + 'id' => 'type', + 'class' => 'form-control select2' + ]) }} +

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

+
+ +
+
+
{{ Form::label('price', 'Price:') }} @component('admin.components.info') - This is the price of a ticket for a passenger + This is the price of a ticket or price per {{ setting('units.weight') }} @endcomponent {{ Form::text('price', null, ['class' => 'form-control', 'placeholder' => 0]) }}

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

@@ -39,16 +54,17 @@
{{ Form::label('cost', 'Cost:') }} @component('admin.components.info') - The operating cost + The operating cost per unit (passenger or {{ setting('units.weight') }}) @endcomponent {{ Form::number('cost', null, ['class' => 'form-control', 'placeholder' => 0, 'step' => '0.01']) }}

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

- +
+
{{ Form::label('capacity', 'Capacity:') }} @component('admin.components.info') - The number of seats available in this class. + Max seats or capacity available. This can be adjusted in the subfleet @endcomponent {{ Form::number('capacity', null, ['class' => 'form-control', 'min' => 0]) }}

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

@@ -56,10 +72,15 @@
{{ Form::label('notes', 'Notes:') }} + @component('admin.components.info') + Notes for this fare + @endcomponent {{ Form::text('notes', null, ['class' => 'form-control']) }}

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

+
+
{{ Form::label('active', 'Active:') }} @@ -68,7 +89,8 @@ {{ Form::checkbox('active', 1, null) }}
- +
+
diff --git a/resources/views/admin/subfleets/fares.blade.php b/resources/views/admin/subfleets/fares.blade.php index 6594e83f..b99d8ebb 100644 --- a/resources/views/admin/subfleets/fares.blade.php +++ b/resources/views/admin/subfleets/fares.blade.php @@ -14,6 +14,7 @@ Name Code + Type Capacity (default) Price (default) Cost (default) @@ -24,16 +25,17 @@ @foreach($subfleet->fares as $atf) - {{ $atf->name }} - {{ $atf->code }} - + {{ $atf->name }} + {{ $atf->code }} + {{ \App\Models\Enums\FareType::label($atf->type) }} + {{ $atf->pivot->capacity }} ({{ $atf->capacity }}) - + {{ $atf->pivot->price }} ({{ $atf->price }}) - + {{ $atf->pivot->cost }} ({{ $atf->cost}}) diff --git a/resources/views/admin/subfleets/fields.blade.php b/resources/views/admin/subfleets/fields.blade.php index 2aaace6c..a58b1725 100644 --- a/resources/views/admin/subfleets/fields.blade.php +++ b/resources/views/admin/subfleets/fields.blade.php @@ -1,32 +1,36 @@
-
- @component('admin.components.info') - Subfleets are aircraft groups. The "type" is a short name. Airlines always - group aircraft together by feature, so 737s with winglets might have a type of - "B.738-WL". You can create as many as you want, you need at least one, though. +
+
+
+ @component('admin.components.info') + Subfleets are aircraft groups. The "type" is a short name. Airlines always + group aircraft together by feature, so 737s with winglets might have a type of + "B.738-WL". You can create as many as you want, you need at least one, though. - Read more about subfleets here. - @endcomponent + Read more about subfleets here. + @endcomponent +
+
+
+
+ {{ Form::label('airline_id', 'Airline:') }} + {{ Form::select('airline_id', $airlines, null , ['class' => 'form-control select2']) }} +

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

+
+ +
+ {{ Form::label('type', 'Type:') }} + {{ Form::text('type', null, ['class' => 'form-control']) }} +

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

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

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

+
+
- -
- {{ Form::label('airline_id', 'Airline:') }} - {{ Form::select('airline_id', $airlines, null , ['class' => 'form-control select2']) }} -

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

-
- -
- {{ Form::label('type', 'Type:') }} - {{ Form::text('type', null, ['class' => 'form-control']) }} -

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

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

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

-
-
diff --git a/resources/views/layouts/default/pireps/fares.blade.php b/resources/views/layouts/default/pireps/fares.blade.php index ab2cf111..3d74d038 100644 --- a/resources/views/layouts/default/pireps/fares.blade.php +++ b/resources/views/layouts/default/pireps/fares.blade.php @@ -7,7 +7,7 @@ @foreach($aircraft->subfleet->fares as $fare)
- {{Form::label('fare_'.$fare->id, $fare->name.' ('.$fare->code.')')}} + {{Form::label('fare_'.$fare->id, $fare->name.' ('. \App\Models\Enums\FareType::label($fare->type).', code '.$fare->code.')')}}
{{ Form::number('fare_'.$fare->id, null, ['class' => 'form-control', 'min' => 0]) }}