From 30be7c245c72bc05ce9f925eac79ec92feb6d6a9 Mon Sep 17 00:00:00 2001 From: "B.Fatih KOZ" <74361521+FatihKoz@users.noreply.github.com> Date: Thu, 20 May 2021 02:01:33 +0300 Subject: [PATCH] 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 ! --- app/Services/Finance/PirepFinanceService.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Services/Finance/PirepFinanceService.php b/app/Services/Finance/PirepFinanceService.php index d8c6a35d..f5150950 100644 --- a/app/Services/Finance/PirepFinanceService.php +++ b/app/Services/Finance/PirepFinanceService.php @@ -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();