From bbd02bf5c7c6759c1da58368fd7d2cee529ac2df Mon Sep 17 00:00:00 2001 From: "B.Fatih KOZ" <74361521+FatihKoz@users.noreply.github.com> Date: Fri, 19 Mar 2021 23:42:36 +0300 Subject: [PATCH] Fix For GH Costs (#1088) * Fix For GH Costs. PR aims to fix the problem where Airport GH cost is not defined but recored to db as 0.00 or 0 (default value for airports table) In such cases settings/default apt gh cost will be used. * Updated logic for JetA1 cost check * Remove default costs being used during import --- app/Services/Finance/PirepFinanceService.php | 14 ++++++++++++-- app/Services/Importers/AirportImporter.php | 8 ++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/Services/Finance/PirepFinanceService.php b/app/Services/Finance/PirepFinanceService.php index e6b81e0f..c0435235 100644 --- a/app/Services/Finance/PirepFinanceService.php +++ b/app/Services/Finance/PirepFinanceService.php @@ -153,7 +153,12 @@ class PirepFinanceService extends Service { $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 (empty($ap->fuel_jeta_cost)) { + $fuel_cost = setting('airports.default_jet_a_fuel_cost'); + } else { + $fuel_cost = $ap->fuel_jeta_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 @@ -546,7 +551,12 @@ class PirepFinanceService extends Service */ public function getGroundHandlingCost(Pirep $pirep, Airport $airport): ?float { - $gh_cost = $airport->ground_handling_cost ?? setting('airports.default_ground_handling_cost'); + if (empty($airport->ground_handling_cost)) { + $gh_cost = setting('airports.default_ground_handling_cost'); + } else { + $gh_cost = $airport->ground_handling_cost; + } + if (!filled($pirep->aircraft->subfleet->ground_handling_multiplier)) { return $gh_cost; } diff --git a/app/Services/Importers/AirportImporter.php b/app/Services/Importers/AirportImporter.php index 68f1652d..61343675 100644 --- a/app/Services/Importers/AirportImporter.php +++ b/app/Services/Importers/AirportImporter.php @@ -31,12 +31,12 @@ class AirportImporter extends BaseImporter $ground_handling_cost = (float) $row->ground_handling_cost; $fuel_jetA_cost = (float) $row->fuel_jeta_cost; - if ($ground_handling_cost === null && $ground_handling_cost !== 0) { - $ground_handling_cost = (float) setting('general.default_ground_handling_cost'); + if (empty($ground_handling_cost)) { + $ground_handling_cost = 0; } - if ($fuel_jetA_cost === null && $fuel_jetA_cost !== 0) { - $fuel_jetA_cost = (float) setting('general.default_jetA_fuel_cost'); + if (empty($fuel_jetA_cost)) { + $fuel_jetA_cost = 0; } $attrs = [