Skip to content

Commit

Permalink
fix paid schedules showing as upcoming in the account (#4188)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-fidd authored Jan 18, 2025
1 parent 91c4e3e commit eb31071
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
26 changes: 15 additions & 11 deletions packages/loot-core/src/client/data-hooks/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
extractScheduleConds,
getNextDate,
getUpcomingDays,
scheduleIsRecurring,
} from '../../shared/schedules';
import { ungroupTransactions } from '../../shared/transactions';
import {
Expand Down Expand Up @@ -169,24 +170,27 @@ export function usePreviewTransactions(): UsePreviewTransactionsResult {
const { date: dateConditions } = extractScheduleConds(
schedule._conditions,
);
let day = d.startOfDay(parseDate(schedule.next_date));

const status = statuses.get(schedule.id);
const isRecurring = scheduleIsRecurring(dateConditions);

const dates: string[] = [];
let day = d.startOfDay(parseDate(schedule.next_date));
if (isRecurring) {
while (day <= upcomingPeriodEnd) {
const nextDate = getNextDate(dateConditions, day);

const dates: Set<string> = new Set();
while (day <= upcomingPeriodEnd) {
const nextDate = getNextDate(dateConditions, day);
if (parseDate(nextDate) > upcomingPeriodEnd) break;

if (status === 'paid' && day.getTime() === today.getTime()) {
dates.push(nextDate);
day = parseDate(addDays(nextDate, 1));
continue;
}
} else {
dates.push(getNextDate(dateConditions, day));
}

if (dates.has(nextDate)) break;
if (parseDate(nextDate) > upcomingPeriodEnd) break;

dates.add(nextDate);
day = parseDate(addDays(nextDate, 1));
if (status === 'paid') {
dates.shift();
}

const schedules: {
Expand Down
7 changes: 7 additions & 0 deletions packages/loot-core/src/shared/schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,10 @@ export function getUpcomingDays(upcomingLength = '7') {
return parseInt(upcomingLength, 10);
}
}

export function scheduleIsRecurring(dateCond) {
const cond = new Condition(dateCond.op, 'date', dateCond.value, null);
const value = cond.getValue();

return value.type === 'recur';
}
6 changes: 6 additions & 0 deletions upcoming-release-notes/4188.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [matt-fidd]
---

Fix paid schedules showing as upcoming in the account

0 comments on commit eb31071

Please sign in to comment.