39e407644d
- Expand BAS reference from ~180 to ~1,276 accounts (full BAS Kontoplan 2026) with K2 exclusion flags, per-class data files, and computed SRU codes - Evolve invoice inbox into unified document inbox handling invoices, receipts, and government letters with AI-powered classification (Claude Haiku Vision) - Add multi-pass document-to-transaction matching engine with greedy assignment for both supplier invoices (reference/amount/date/name) and receipts (weighted amount/merchant/date scoring) - Add supplier invoice matching in transaction ingest pipeline - Inject booking template suggestions into AI extraction prompts - Surface matched documents in swipe categorization UI with one-tap booking - Auto-activate missing BAS accounts during SIE import against full reference - Add K2 filter toggle in Chart of Accounts manager - Add receipt confirmation route with BFNAR representation fields - Add database migrations for K2 support and document matching columns - Remove obsolete extension migration scripts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
32 lines
1009 B
TypeScript
32 lines
1009 B
TypeScript
import { createClient } from '@/lib/supabase/server'
|
|
import { NextResponse } from 'next/server'
|
|
import { runDocumentMatchingSweep } from '@/lib/documents/batch-match'
|
|
|
|
export async function POST(request: Request) {
|
|
const supabase = await createClient()
|
|
const { data: { user } } = await supabase.auth.getUser()
|
|
|
|
if (!user) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
// Optional: pass specific inbox item IDs to match
|
|
let inboxItemIds: string[] | undefined
|
|
try {
|
|
const body = await request.json()
|
|
if (Array.isArray(body?.inboxItemIds)) {
|
|
inboxItemIds = body.inboxItemIds
|
|
}
|
|
} catch {
|
|
// No body or invalid JSON — sweep all unmatched items
|
|
}
|
|
|
|
try {
|
|
const result = await runDocumentMatchingSweep(supabase, user.id, inboxItemIds)
|
|
return NextResponse.json({ data: result })
|
|
} catch (error) {
|
|
console.error('[match-sweep] Failed:', error)
|
|
return NextResponse.json({ error: 'Match sweep failed' }, { status: 500 })
|
|
}
|
|
}
|