Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Fuel and Ground Handling Costs #1050

Merged
merged 14 commits into from
Mar 18, 2021
16 changes: 11 additions & 5 deletions app/Services/Finance/PirepFinanceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public function payFaresForPirep($pirep): void
public function payFuelCosts(Pirep $pirep): void
{
$ap = $pirep->dpt_airport;
// Get Airport Fuel Cost or revert back to settings
$fuel_cost = $ap->fuel_jeta_cost ?? setting('airports.default_jet_a_fuel_cost');
if (setting('pirep.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
Expand All @@ -173,15 +175,15 @@ public function payFuelCosts(Pirep $pirep): void
$fuel_amount = $pirep->fuel_used;
}

$debit = Money::createFromAmount($fuel_amount * $ap->fuel_jeta_cost);
Log::info('Finance: Fuel cost, (fuel='.$fuel_amount.', cost='.$ap->fuel_jeta_cost.') D='
$debit = Money::createFromAmount($fuel_amount * $fuel_cost);
Log::info('Finance: Fuel cost, (fuel='.$fuel_amount.', cost='.$fuel_cost.') D='
.$debit->getAmount());

$this->financeSvc->debitFromJournal(
$pirep->airline->journal,
$debit,
$pirep,
'Fuel Cost ('.$ap->fuel_jeta_cost.'/'.config('phpvms.internal_units.fuel').')',
'Fuel Cost ('.$fuel_cost.'/'.config('phpvms.internal_units.fuel').')',
'Fuel',
'fuel'
);
Expand Down Expand Up @@ -531,17 +533,21 @@ public function getReconciledFaresForPirep($pirep)
*/
public function getGroundHandlingCost(Pirep $pirep)
{
// Get Airport GH Costs for Departure and Arrival or revert back to settings
$dpt_gh_cost = $pirep->dpt_airport->ground_handling_cost ?? setting('airports.default_ground_handling_cost');
$arr_gh_cost = $pirep->arr_airport->ground_handling_cost ?? setting('airports.default_ground_handling_cost');
$gh_cost = $dpt_gh_cost + $arr_gh_cost;
FatihKoz marked this conversation as resolved.
Show resolved Hide resolved
if (filled($pirep->aircraft->subfleet->ground_handling_multiplier)) {
// force into percent mode
$multiplier = $pirep->aircraft->subfleet->ground_handling_multiplier.'%';

return Math::applyAmountOrPercent(
$pirep->arr_airport->ground_handling_cost,
$gh_cost,
$multiplier
);
}

return $pirep->arr_airport->ground_handling_cost;
return $gh_cost;
}

/**
Expand Down