34
app/Database/migrations/2020_03_06_141153_fares_add_type.php
Normal file
34
app/Database/migrations/2020_03_06_141153_fares_add_type.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Enums\FareType;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class FaresAddType extends Migration
|
||||
{
|
||||
/**
|
||||
* Add a `pilot_pay` column for a fixed amount to pay to a pilot for a flight
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('fares', function (Blueprint $table) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
|
||||
16
app/Models/Enums/FareType.php
Normal file
16
app/Models/Enums/FareType.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Enums;
|
||||
|
||||
use App\Contracts\Enum;
|
||||
|
||||
class FareType extends Enum
|
||||
{
|
||||
public const PASSENGER = 0;
|
||||
public const CARGO = 1;
|
||||
|
||||
public static $labels = [
|
||||
self::PASSENGER => 'Passenger',
|
||||
self::CARGO => 'Cargo',
|
||||
];
|
||||
}
|
||||
@@ -78,4 +78,9 @@ class Expense extends Model
|
||||
{
|
||||
return $this->belongsTo(Airline::class, 'airline_id');
|
||||
}
|
||||
|
||||
public function ref_model()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user