fix: move batchRefs fetch after records is filled (linked batch ref on /invoices)

This commit is contained in:
Ysterbaard 2026-09-18 20:06:40 +02:00
parent 14586a6e4f
commit a50990d88f

View file

@ -27,24 +27,6 @@ export default async function InvoicesPage({
let records: any[] = [];
// Fetch batch refs for any invoices that have a payment_batch, so we can
// show "Paid · BATCH-REF" instead of just "Paid".
const batchRefs = new Map<string, string>(); // batchId -> batch_ref
const batchIds = Array.from(new Set(records.map((r) => r.payment_batch).filter((x) => x && x !== "")));
if (batchIds.length > 0) {
try {
// PB filter syntax: field="id1" || field="id2" || ...
const filter = batchIds.map((id) => `id="${id}"`).join(" || ");
const br = await pb.collection("JEI_payment_batches").getList(1, 500, {
filter,
fields: "id,batch_ref",
});
for (const b of br.items) batchRefs.set(b.id, b.batch_ref);
} catch (_) {
// best-effort; status will fall back to "Paid (no ref)"
}
}
try {
// Don't pass filter when empty — the SDK serializes `undefined` as the
// literal string "undefined" which PB rejects with 400.
@ -75,6 +57,24 @@ export default async function InvoicesPage({
);
}
// Fetch batch refs for any invoices that have a payment_batch, so we can
// show "Paid · BATCH-REF" instead of just "Paid".
const batchRefs = new Map<string, string>(); // batchId -> batch_ref
const batchIds = Array.from(new Set(records.map((r) => r.payment_batch).filter((x) => x && x !== "")));
if (batchIds.length > 0) {
try {
// PB filter syntax: field="id1" || field="id2" || ...
const filter = batchIds.map((id) => `id="${id}"`).join(" || ");
const br = await pb.collection("JEI_payment_batches").getList(1, 500, {
filter,
fields: "id,batch_ref",
});
for (const b of br.items) batchRefs.set(b.id, b.batch_ref);
} catch (_) {
// best-effort; status will fall back to "Paid (no ref)"
}
}
return (
<div className="space-y-6">
<div className="flex items-center justify-between">