Date filter feature (#24)

* feat: add date sorting support to journal entries API

Add sort_date query parameter (asc/desc) that orders results by
entry_date instead of the default voucher_series + voucher_number.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add date sort toggle to journal entry list

Add ascending/descending sort button next to the missing attachment
filter. Defaults to newest first, toggles between nyast/äldst först.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add date range filter inputs to journal entry list

Add Från/Till text inputs (YYYY-MM-DD) for filtering entries by date
range. Applies on blur or Enter, with an X button to clear both fields.
Both fields are optional and work independently of the sort toggle.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Mattsson
2026-03-13 17:05:32 +01:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 2ad8731dc9
commit a438c50e9c
2 changed files with 102 additions and 20 deletions
+15 -3
View File
@@ -22,14 +22,26 @@ export async function GET(request: Request) {
const offset = parseInt(searchParams.get('offset') || '0')
const dateFrom = searchParams.get('date_from')
const dateTo = searchParams.get('date_to')
const sortDate = searchParams.get('sort_date') // 'asc' | 'desc'
const dateAscending = sortDate === 'asc'
let query = supabase
.from('journal_entries')
.select('*, lines:journal_entry_lines(*)', { count: 'exact' })
.eq('user_id', user.id)
.order('voucher_series', { ascending: true })
.order('voucher_number', { ascending: true })
.range(offset, offset + limit - 1)
if (sortDate === 'asc' || sortDate === 'desc') {
query = query
.order('entry_date', { ascending: dateAscending })
.order('voucher_number', { ascending: dateAscending })
} else {
query = query
.order('voucher_series', { ascending: true })
.order('voucher_number', { ascending: true })
}
query = query.range(offset, offset + limit - 1)
if (periodId) {
query = query.eq('fiscal_period_id', periodId)