diff --git a/app/invoices/page.tsx b/app/invoices/page.tsx index b872e69..4d8d9ee 100644 --- a/app/invoices/page.tsx +++ b/app/invoices/page.tsx @@ -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(); // 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(); // 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 (