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>
This commit is contained in:
B.Fatih KOZ 2021-05-06 15:16:33 +03:00 committed by GitHub
parent b6c0946795
commit d2272e32a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 8 deletions

View File

@ -144,6 +144,20 @@
options:
type: text
description: If an airport's Jet A Fuel Cost isn't added, set this value by default
- key: airports.default_100ll_fuel_cost
name: 'Default 100LL Fuel Cost'
group: airports
value: 0.9
options:
type: text
description: If an airport's 100LL Fuel Cost isn't added, set this value by default
- key: airports.default_mogas_fuel_cost
name: 'Default MOGAS Fuel Cost'
group: airports
value: 0.8
options:
type: text
description: If an airport's MOGAS Fuel Cost isn't added, set this value by default
- key: bids.disable_flight_on_bid
name: 'Disable flight on bid'
group: bids

View File

@ -20,6 +20,7 @@ use App\Models\Traits\FilesTrait;
* @property float cost_delay_minute
* @property Airline airline
* @property Airport hub
* @property int fuel_type
*/
class Subfleet extends Model
{

View File

@ -8,7 +8,10 @@ use App\Models\Aircraft;
use App\Models\Airport;
use App\Models\Enums\ExpenseType;
use App\Models\Enums\FareType;
use App\Models\Enums\FuelType;
use App\Models\Enums\PirepSource;
use App\Models\Enums\PirepState;
use App\Models\Enums\PirepStatus;
use App\Models\Expense;
use App\Models\Pirep;
use App\Models\Subfleet;
@ -151,18 +154,37 @@ class PirepFinanceService extends Service
*/
public function payFuelCosts(Pirep $pirep): void
{
// Get Airport Fuel Prices or Use Defaults
$ap = $pirep->dpt_airport;
// Get Airport Fuel Cost or revert back to settings
if (empty($ap->fuel_jeta_cost)) {
$fuel_cost = setting('airports.default_jet_a_fuel_cost');
// Get Aircraft Fuel Type from Subfleet
// And set $fuel_cost according to type (Failsafe is Jet A)
$sf = $pirep->aircraft->subfleet;
if ($sf) {
$fuel_type = $sf->fuel_type;
} else {
$fuel_cost = $ap->fuel_jeta_cost;
$fuel_type = FuelType::JET_A;
}
if ($fuel_type === FuelType::LOW_LEAD) {
$fuel_cost = !empty($ap->fuel_100ll_cost) ? $ap->fuel_100ll_cost : setting('airports.default_100ll_fuel_cost');
} elseif ($fuel_type === FuelType::MOGAS) {
$fuel_cost = !empty($ap->fuel_mogas_cost) ? $ap->fuel_mogas_cost : setting('airports.default_mogas_fuel_cost');
} else { // Default to JetA
$fuel_cost = !empty($ap->fuel_jeta_cost) ? $ap->fuel_jeta_cost : setting('airports.default_jet_a_fuel_cost');
}
if (setting('pireps.advanced_fuel', false)) {
$ac = $pirep->aircraft;
// Reading second row by skip(1) to reach the previous accepted pirep. Current pirep is at the first row
$prev_flight = Pirep::where('aircraft_id', $ac->id)->where('state', 2)->where('status', 'ONB')->orderby('submitted_at', 'desc')->skip(1)->first();
$prev_flight = Pirep::where([
'aircraft_id' => $pirep->aircraft->id,
'state' => PirepState::ACCEPTED,
'status' => PirepStatus::ARRIVED,
])
->orderby('submitted_at', 'desc')
->skip(1)
->first();
if ($prev_flight) {
// If there is a pirep use its values to calculate the remaining fuel
// and calculate the uplifted fuel amount for this pirep
@ -181,8 +203,7 @@ class PirepFinanceService extends Service
}
$debit = Money::createFromAmount($fuel_amount * $fuel_cost);
Log::info('Finance: Fuel cost, (fuel='.$fuel_amount.', cost='.$fuel_cost.') D='
.$debit->getAmount());
Log::info('Finance: Fuel cost, (fuel='.$fuel_amount.', cost='.$fuel_cost.') D='.$debit->getAmount());
$this->financeSvc->debitFromJournal(
$pirep->airline->journal,