fix(subscriptions): a payment made around a past due date counts as paid, runway refetches on focus

A bill paid a day before its due date showed as overdue in the runway
because past due dates were never matched against payments; now any
payment within a third of the cycle around the date settles it. The
runway's bills and payments refetch when the tab gets focus, so entries
the bot made meanwhile show up.
This commit is contained in:
hh committed 2026-10-18 17:02:12 +00:00
1 parent 4a03ab8e1a
commit 9c15b81409
2 files changed
+3 -5

No files matched your search

+2
View File
@@ -28,10 +28,12 @@ export const runwayQueries = {
bills: (start: string, end: string) => ({ bills: (start: string, end: string) => ({
queryFn: () => all<Bill>("/v1/bills", { end, start }), queryFn: () => all<Bill>("/v1/bills", { end, start }),
queryKey: ["subscriptions", "runway", start, end], queryKey: ["subscriptions", "runway", start, end],
refetchOnWindowFocus: true,
}), }),
paid: () => ({ paid: () => ({
queryFn: async () => toPayments(await search("has_any_bill:true")), queryFn: async () => toPayments(await search("has_any_bill:true")),
queryKey: ["subscriptions", "payments"], queryKey: ["subscriptions", "payments"],
refetchOnWindowFocus: true,
}), }),
unlinked: (day: string) => { unlinked: (day: string) => {
const after = addDays(day, -UNLINKED_DAYS); const after = addDays(day, -UNLINKED_DAYS);
+1 -5
View File
@@ -208,11 +208,7 @@ function occurrences(bill: Bill, day: string) {
return (bill.pay_dates ?? []) return (bill.pay_dates ?? [])
.map((raw) => raw.slice(0, 10)) .map((raw) => raw.slice(0, 10))
.filter((date) => !end || date <= end) .filter((date) => !end || date <= end)
.filter( .filter((date) => !paid.some((p) => Math.abs(daysBetween(p, date)) < early))
(date) =>
date < day ||
!paid.some((p) => p <= date && daysBetween(p, date) < early)
)
.map((date) => ({ date: date < day ? day : date, overdue: date < day })); .map((date) => ({ date: date < day ? day : date, overdue: date < day }));
} }