Accounting Banking: page through all register transactions

The bank register fetched transactions in a single request, which
PostgREST caps at 1000 rows. An imported bank account with a longer
register (e.g. Bridgewater Checking, ~1,500 rows) truncated, throwing
off the displayed running balance. Page through all rows ordered by a
stable key (date, created_at, id).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-09 13:30:19 -04:00
parent bd4c385478
commit ea2f2a089a
+17 -4
View File
@@ -172,16 +172,29 @@ export default function AccountingBankingPage() {
const { data: txs = [] } = useQuery({ const { data: txs = [] } = useQuery({
queryKey: ["transactions", cid, activeAccountId], queryKey: ["transactions", cid, activeAccountId],
enabled: !!cid && !!activeAccountId, enabled: !!cid && !!activeAccountId,
queryFn: async () => queryFn: async () => {
( // PostgREST caps each response at 1000 rows; an account with a long
await accounting // register (e.g. an imported bank account) would truncate, throwing off
// the running balance. Page through all rows ordered by a stable key.
const PAGE = 1000;
const out: any[] = [];
for (let offset = 0; ; offset += PAGE) {
const { data, error } = await accounting
.from("transactions") .from("transactions")
.select("*, bank_account:accounts!account_id(name), coa:accounts!coa_account_id(name), vendors(name), customers(name)") .select("*, bank_account:accounts!account_id(name), coa:accounts!coa_account_id(name), vendors(name), customers(name)")
.eq("company_id", cid) .eq("company_id", cid)
.eq("account_id", activeAccountId) .eq("account_id", activeAccountId)
.order("date", { ascending: true }) .order("date", { ascending: true })
.order("created_at", { ascending: true }) .order("created_at", { ascending: true })
).data ?? [], .order("id", { ascending: true })
.range(offset, offset + PAGE - 1);
if (error) throw error;
const rows = data ?? [];
out.push(...rows);
if (rows.length < PAGE) break;
}
return out;
},
}); });
const register = useMemo(() => { const register = useMemo(() => {