Skip to content

A local-first personal finance app

fix paid schedules showing as upcoming in the account (#4188)

Matt Fiddamaneb31071043bc
diff --git a/packages/loot-core/src/client/data-hooks/transactions.ts b/packages/loot-core/src/client/data-hooks/transactions.ts
index b2f2103c2b..5c3bc32e3a 100644
--- a/packages/loot-core/src/client/data-hooks/transactions.ts
+++ b/packages/loot-core/src/client/data-hooks/transactions.ts
@@ -12,6 +12,7 @@ import {
extractScheduleConds,
getNextDate,
getUpcomingDays,
+ scheduleIsRecurring,
} from '../../shared/schedules';
import { ungroupTransactions } from '../../shared/transactions';
import {
@@ -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: {
diff --git a/packages/loot-core/src/shared/schedules.ts b/packages/loot-core/src/shared/schedules.ts
index d6afb9cb0c..127ee21477 100644
--- a/packages/loot-core/src/shared/schedules.ts
+++ b/packages/loot-core/src/shared/schedules.ts
@@ -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';
+}
diff --git a/upcoming-release-notes/4188.md b/upcoming-release-notes/4188.md
new file mode 100644
index 0000000000..f92935a96d
--- /dev/null
+++ b/upcoming-release-notes/4188.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [matt-fidd]
+---
+
+Fix paid schedules showing as upcoming in the account