* Refactor bookkeeping error handling and introduce new error classes - Introduced new error classes for better error categorization: - JournalEntryNotBalancedError - FiscalPeriodNotFoundError - EntryDateOutsideFiscalPeriodError - JournalEntryNotFoundError - CannotReverseNonPostedError - CannotCorrectNonPostedError - EntryAlreadyReversedError - CurrencyRevaluationAlreadyExistsError - InvalidMappingResultError - BookkeepingDatabaseError - Updated existing functions in engine.ts and transaction-entries.ts to throw specific errors instead of generic ones. - Enhanced error response handling in get-error-message.ts to provide localized messages for new error types. - Added unit tests for new error classes and error handling functions to ensure correctness and coverage. * feat(ai): implement AI proposal application and persistence - Add apply.ts to handle the application of AI proposals, including match and booking steps. - Introduce persist.ts for inserting and managing AI requests and proposals, ensuring unique constraints. - Create re-validate.ts for validating proposals before acceptance, checking for stale conditions. - Define database migrations for ai_requests and ai_proposals tables, including constraints and indexes. - Enhance journal_entries with AI provenance tracking, linking entries to AI proposals. - Update categorization_templates to distinguish AI-corrected templates. - Add company settings for toggling AI flow and managing backfill processes. - Extend processing_history to include AI-related events for better tracking. * feat: add uncategorized transactions API and UI for transaction selection - Implemented a new API endpoint for fetching uncategorized transactions with pagination and filtering options. - Created ChangeTransactionDialog component for selecting alternative transactions based on AI proposals. - Developed ReceiptDetailDialog to display detailed information about receipts, including upload functionality. - Added TransactionDetailDialog for viewing transaction details with links to the transaction list. - Introduced receipt quality assessment logic to evaluate extracted receipt data. - Implemented feature flagging for the AI bookkeeping agent to control availability in different environments. * feat: add manual receipt extraction dialog and integrate AWS Textract for expense analysis - Added ManualExtractDialog component for user input when AI fails to extract receipt data. - Implemented ReceiptsList component to manage and display uploaded receipts, including upload and rescan functionalities. - Introduced Textract integration for analyzing expenses, extracting fields like total, vendor, and date. - Updated package.json to include @aws-sdk/client-textract dependency. * fix(ai): handle livsmedel VAT transition (12% → 6%) in booking prompt and re-validate guard Add date-aware guidance to BOOKING_SYSTEM_PROMPT for the temporary livsmedel VAT cut (Prop. 2025/26:55, 2026-04-01 to 2027-12-31), with restaurang/servering carve-out at 12%. Add a re-validate safety net that rejects clearly-stale rate labels for grocery-chain merchants relative to the entry date. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
123 lines
4.3 KiB
TypeScript
123 lines
4.3 KiB
TypeScript
'use client'
|
|
|
|
import Link from 'next/link'
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from '@/components/ui/dialog'
|
|
import { Button } from '@/components/ui/button'
|
|
import { ExternalLink } from 'lucide-react'
|
|
import { formatCurrency, formatDate } from '@/lib/utils'
|
|
import type { AgentInboxItemView } from '@/app/(dashboard)/agent-inbox/page'
|
|
|
|
interface Props {
|
|
open: boolean
|
|
onOpenChange: (open: boolean) => void
|
|
tx: NonNullable<AgentInboxItemView['transaction']>
|
|
}
|
|
|
|
export default function TransactionDetailDialog({ open, onOpenChange, tx }: Props) {
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent className="max-w-lg">
|
|
<DialogHeader>
|
|
<DialogTitle className="flex items-baseline justify-between gap-3">
|
|
<span className="truncate">{tx.description || 'Okänd transaktion'}</span>
|
|
<span className="tabular-nums text-base font-medium flex-shrink-0">
|
|
{formatCurrency(tx.amount, tx.currency)}
|
|
</span>
|
|
</DialogTitle>
|
|
<DialogDescription>
|
|
{formatDate(tx.date)} · Banktransaktion
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<div className="space-y-4 text-sm">
|
|
<dl className="grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1.5">
|
|
{tx.merchant_name && tx.merchant_name !== tx.description && (
|
|
<>
|
|
<dt className="text-muted-foreground">Handlare</dt>
|
|
<dd>{tx.merchant_name}</dd>
|
|
</>
|
|
)}
|
|
<dt className="text-muted-foreground">Kategori</dt>
|
|
<dd>{tx.category ?? '—'}</dd>
|
|
<dt className="text-muted-foreground">Affärs/privat</dt>
|
|
<dd>
|
|
{tx.is_business === true
|
|
? 'Affärs'
|
|
: tx.is_business === false
|
|
? 'Privat'
|
|
: 'Okänt'}
|
|
</dd>
|
|
{tx.currency && tx.currency !== 'SEK' && (
|
|
<>
|
|
<dt className="text-muted-foreground">Valuta</dt>
|
|
<dd>
|
|
{tx.currency}
|
|
{tx.amount_sek != null && (
|
|
<span className="text-muted-foreground">
|
|
{' '}
|
|
({formatCurrency(tx.amount_sek, 'SEK')})
|
|
</span>
|
|
)}
|
|
</dd>
|
|
{tx.exchange_rate != null && (
|
|
<>
|
|
<dt className="text-muted-foreground">Växelkurs</dt>
|
|
<dd className="tabular-nums">{tx.exchange_rate}</dd>
|
|
</>
|
|
)}
|
|
{tx.exchange_rate_date && (
|
|
<>
|
|
<dt className="text-muted-foreground">Kursdatum</dt>
|
|
<dd>{formatDate(tx.exchange_rate_date)}</dd>
|
|
</>
|
|
)}
|
|
</>
|
|
)}
|
|
{tx.mcc_code != null && (
|
|
<>
|
|
<dt className="text-muted-foreground">MCC-kod</dt>
|
|
<dd className="font-mono">{tx.mcc_code}</dd>
|
|
</>
|
|
)}
|
|
{tx.external_id && (
|
|
<>
|
|
<dt className="text-muted-foreground">Externt ID</dt>
|
|
<dd className="font-mono text-xs text-muted-foreground break-all">
|
|
{tx.external_id}
|
|
</dd>
|
|
</>
|
|
)}
|
|
{tx.bank_connection_id && (
|
|
<>
|
|
<dt className="text-muted-foreground">Bankanslutning</dt>
|
|
<dd className="font-mono text-xs text-muted-foreground">
|
|
{tx.bank_connection_id.slice(0, 8)}…
|
|
</dd>
|
|
</>
|
|
)}
|
|
<dt className="text-muted-foreground">Transaktions-ID</dt>
|
|
<dd className="font-mono text-xs text-muted-foreground break-all">
|
|
{tx.id}
|
|
</dd>
|
|
</dl>
|
|
|
|
<div className="pt-3 border-t">
|
|
<Button variant="outline" size="sm" asChild>
|
|
<Link href={`/transactions?highlight=${tx.id}`}>
|
|
<ExternalLink className="h-3.5 w-3.5 mr-2" />
|
|
Öppna i transaktionslistan
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|