Minor fixes

This commit is contained in:
Jakob Wennberg
2026-02-21 16:03:38 +01:00
parent 327ecd4ff2
commit 358be27e24
3 changed files with 11 additions and 7 deletions
+2 -2
View File
@@ -391,7 +391,7 @@ export default function NewInvoicePage() {
<div className="space-y-4">
{fields.map((field, index) => (
<div key={field.id} className="grid gap-4 md:grid-cols-12 items-start">
<div className="md:col-span-4 space-y-2">
<div className="md:col-span-3 space-y-2">
<Label>Beskrivning</Label>
<Input
placeholder="T.ex. Instagram-kampanj"
@@ -403,7 +403,7 @@ export default function NewInvoicePage() {
</p>
)}
</div>
<div className="md:col-span-1 space-y-2">
<div className="md:col-span-2 space-y-2">
<Label>Antal</Label>
<Input
type="number"
@@ -32,9 +32,9 @@ async function ensureFiscalPeriod(
.lte('period_start', date)
.gte('period_end', date)
.eq('is_closed', false)
.single()
.limit(1)
if (existing) {
if (existing && existing.length > 0) {
return true
}
+7 -3
View File
@@ -90,6 +90,9 @@ export async function findFiscalPeriod(
): Promise<string | null> {
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
}
/**