phpvms/app/Models/Subfleet.php
B.Fatih KOZ d2272e32a6
100LL and MOGAS Fuel Cost (#1172)
* Add defaults for 100LL and MOGAS prices

Add missing defaults for 100LL and MOGAS Fuel prices.

* Calculate Fuel Cost according to Fuel Type

Calculate pirep fuel costs according to aircraft (subfleet) fuel type, use JetA as fail safe default.

* Fix for Failing AwardTest

At least attempting to fix

* Fix fuel types logic

* Style

* Invert the logic

Co-authored-by: Nabeel Shahzad <nabeel@nabeel.sh>
2021-05-06 08:16:33 -04:00

111 lines
2.7 KiB
PHP

<?php
namespace App\Models;
use App\Contracts\Model;
use App\Models\Enums\AircraftStatus;
use App\Models\Traits\ExpensableTrait;
use App\Models\Traits\FilesTrait;
/**
* @property int id
* @property string type
* @property string simbrief_type
* @property string name
* @property int airline_id
* @property int hub_id
* @property string ground_handling_multiplier
* @property Fare[] fares
* @property float cost_block_hour
* @property float cost_delay_minute
* @property Airline airline
* @property Airport hub
* @property int fuel_type
*/
class Subfleet extends Model
{
use ExpensableTrait;
use FilesTrait;
public $fillable = [
'airline_id',
'hub_id',
'type',
'simbrief_type',
'name',
'fuel_type',
'cost_block_hour',
'cost_delay_minute',
'ground_handling_multiplier',
'cargo_capacity',
'fuel_capacity',
'gross_weight',
];
public $table = 'subfleets';
public $casts = [
'airline_id' => 'integer',
'turn_time' => 'integer',
'cost_block_hour' => 'float',
'cost_delay_minute' => 'float',
'fuel_type' => 'integer',
'ground_handling_multiplier' => 'float',
'cargo_capacity' => 'float',
'fuel_capacity' => 'float',
'gross_weight' => 'float',
];
public static $rules = [
'type' => 'required',
'name' => 'required',
'hub_id' => 'nullable',
'ground_handling_multiplier' => 'nullable|numeric',
];
/**
* @param $type
*/
public function setTypeAttribute($type)
{
$type = str_replace([' ', ','], ['-', ''], $type);
$this->attributes['type'] = $type;
}
/**
* Relationships
*/
public function aircraft()
{
return $this->hasMany(Aircraft::class, 'subfleet_id')
->where('status', AircraftStatus::ACTIVE);
}
public function airline()
{
return $this->belongsTo(Airline::class, 'airline_id');
}
public function hub()
{
return $this->hasOne(Airport::class, 'id', 'hub_id');
}
public function fares()
{
return $this->belongsToMany(Fare::class, 'subfleet_fare')
->withPivot('price', 'cost', 'capacity');
}
public function flights()
{
return $this->belongsToMany(Flight::class, 'flight_subfleet');
}
public function ranks()
{
return $this->belongsToMany(Rank::class, 'subfleet_rank')
->withPivot('acars_pay', 'manual_pay');
}
}