Fix Advanced Fuel Calculations (#1190)

* Fix Advanced Fuel Calculations

Current code works fine with a fresh submitted pirep but when a re-calculation is needed, fuel amount will not be correct if the aircraft was flown later on.
Commit provides fix for such re-calculation scenarios.

* StyleFix for the Comment Line !
This commit is contained in:
B.Fatih KOZ
2021-05-20 02:01:33 +03:00
committed by GitHub
parent 7cb9ae4ec3
commit 30be7c245c

View File

@@ -176,11 +176,13 @@ class PirepFinanceService extends Service
if (setting('pireps.advanced_fuel', false)) {
// Reading second row by skip(1) to reach the previous accepted pirep. Current pirep is at the first row
// To get proper fuel values, we need to fetch current pirep and older ones only. Scenario: ReCalculating finances
$prev_flight = Pirep::where([
'aircraft_id' => $pirep->aircraft->id,
'state' => PirepState::ACCEPTED,
'status' => PirepStatus::ARRIVED,
])
->where('submitted_at', '<=', $pirep->submitted_at)
->orderby('submitted_at', 'desc')
->skip(1)
->first();