From 358be27e24568d8e7f426fbd222b713c59cdc1ee Mon Sep 17 00:00:00 2001 From: Jakob Wennberg Date: Sat, 21 Feb 2026 16:03:38 +0100 Subject: [PATCH] Minor fixes --- app/(dashboard)/invoices/new/page.tsx | 4 ++-- app/api/transactions/[id]/categorize/route.ts | 4 ++-- lib/bookkeeping/engine.ts | 10 +++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/(dashboard)/invoices/new/page.tsx b/app/(dashboard)/invoices/new/page.tsx index 0e98da63..5a08981e 100644 --- a/app/(dashboard)/invoices/new/page.tsx +++ b/app/(dashboard)/invoices/new/page.tsx @@ -391,7 +391,7 @@ export default function NewInvoicePage() {
{fields.map((field, index) => (
-
+
)}
-
+
0) { return true } diff --git a/lib/bookkeeping/engine.ts b/lib/bookkeeping/engine.ts index f3de706d..b165f8e7 100644 --- a/lib/bookkeeping/engine.ts +++ b/lib/bookkeeping/engine.ts @@ -90,6 +90,9 @@ export async function findFiscalPeriod( ): Promise { const supabase = await createClient() + // Use limit(1) instead of single() to handle overlapping fiscal periods + // gracefully. When multiple periods cover the same date, we pick the one + // with the latest start date (most specific / narrowest period). const { data, error } = await supabase .from('fiscal_periods') .select('id') @@ -97,13 +100,14 @@ export async function findFiscalPeriod( .lte('period_start', date) .gte('period_end', date) .eq('is_closed', false) - .single() + .order('period_start', { ascending: false }) + .limit(1) - if (error || !data) { + if (error || !data || data.length === 0) { return null } - return data.id + return data[0].id } /**