fix(currency): transaction-date FX rate + mall bookings in SEK (#442) (#483)

* fix(currency): use transaction-date FX rate and post mall bookings in SEK (#442)

Three related defects in non-SEK transaction handling:

1. Ingest priced every transaction in a batch at today's rate because
   fetchMultipleRates() was called without a date. Switch to a per-
   (currency, date) fetch via fetchExchangeRate() + Promise.allSettled,
   so each row stores Riksbanken's rate as of its own transaction date.

2. buildMappingResultFromTemplate emitted VAT/reverse-charge/output-VAT
   lines from Math.abs(transaction.amount) — the source-currency amount.
   Mall bookings on USD/EUR transactions therefore posted the journal
   entry in the wrong currency. Resolve to SEK once via resolveSekAmount()
   and reuse for every line, matching what createTransactionJournalEntry
   already does for the settlement line.

3. The Granska bokföring modal and the journal-entry detail page lacked
   a clear audit trail. The verifikation preview now renders in SEK with
   a separate original-currency subtitle in the header; the detail page
   gains a dedicated "Valutaomräkning" card above Kontorader showing the
   rate and original total.

Also: replace truncate with break-all on the modal description so long
UUID-style strings (e.g. BALANCE_CASHBACK-…) wrap instead of forcing
horizontal overscroll.

Tests: 4 new booking-templates cases (USD 25%, EUR fallback via
exchange_rate, EU reverse-charge on USD, output VAT on USD income) and
2 new ingest cases (per-pair fetch dedup; no fetch for SEK rows).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(currency): wire SEK conversion into SwipeCategorizationView (#442 follow-up)

Address Greptile review:

- SwipeCategorizationView rendered JournalEntryPreview without amountSek,
  so the swipe flow had the same defect QuickReviewDialog had — a USD
  transaction showed the verifikation in source currency labeled SEK.
  Now resolves SEK once via resolveSekAmount, passes it to the preview,
  and shows SEK as the headline with the original-currency subtitle
  (parallel to QuickReviewDialog).
- Drop the now-dead `currency` prop from JournalEntryPreviewProps and
  its remaining call site in QuickReviewDialog — the component
  hardcodes 'SEK' on display, so the prop was misleading.
- Correct the misleading inline comment in ingest.ts: network failures
  resolve inside fetchExchangeRate to getFallbackRate() (non-null),
  so the key only stays unset on empty-observation responses or
  outright rejections.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-05-14 15:00:12 +02:00
committed by GitHub
co-authored by Claude Opus 4.7
parent 4a6c473cc4
commit cad83d180d
8 changed files with 276 additions and 58 deletions
+27 -18
View File
@@ -370,24 +370,6 @@ export default function JournalEntryDetailPage({ params }: { params: Promise<{ i
<span className="text-muted-foreground">Antal rader</span>
<span>{lines.length}</span>
</div>
{hasForeignCurrency && (
<>
<div className="border-t pt-2 mt-2 flex justify-between">
<span className="text-muted-foreground">Belopp i utländsk valuta</span>
<span className="tabular-nums font-medium">
{foreignTotal.toLocaleString('sv-SE', { minimumFractionDigits: 2 })} {foreignCurrency}
</span>
</div>
{foreignExchangeRate && (
<div className="flex justify-between">
<span className="text-muted-foreground">Omräkningskurs</span>
<span className="tabular-nums">
1 {foreignCurrency} = {foreignExchangeRate.toLocaleString('sv-SE', { minimumFractionDigits: 4, maximumFractionDigits: 4 })} SEK
</span>
</div>
)}
</>
)}
</CardContent>
</Card>
@@ -413,6 +395,33 @@ export default function JournalEntryDetailPage({ params }: { params: Promise<{ i
</Card>
</div>
{/* Foreign-currency conversion audit chip */}
{hasForeignCurrency && foreignCurrency && (
<Card>
<CardContent className="p-4">
<p className="text-[11px] font-medium uppercase tracking-wider text-muted-foreground mb-2">
Valutaomräkning
</p>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2 text-sm">
<div className="flex justify-between sm:block">
<span className="text-muted-foreground">Kurs</span>
<span className="tabular-nums sm:block">
{foreignExchangeRate
? `1 ${foreignCurrency} = ${foreignExchangeRate.toLocaleString('sv-SE', { minimumFractionDigits: 4, maximumFractionDigits: 4 })} SEK`
: '—'}
</span>
</div>
<div className="flex justify-between sm:block">
<span className="text-muted-foreground">Ursprungsbelopp</span>
<span className="tabular-nums sm:block">
{foreignTotal.toLocaleString('sv-SE', { minimumFractionDigits: 2 })} {foreignCurrency}
</span>
</div>
</div>
</CardContent>
</Card>
)}
{/* Lines table */}
<Card>
<CardHeader>