Files
accounted/extensions/general/calendar/components/PaymentSummaryCard.tsx
T
Jakob WennbergandClaude Fable 5 aead2bc1d1 fix(ui): stop mislabeling unconverted FX amounts as kr in aggregates and toasts (#1182)
Fixes #1173. invoices.total_sek stays NULL when the Riksbanken rate
fetch fails at creation, and every `total_sek || total` fallback then
treated a raw foreign amount as kronor:

- lib/calendar/utils: new invoiceSekAmount() returns null for
  unconverted non-SEK invoices; period summaries and day totals skip
  them and PeriodSummary exposes unconvertedCount. PaymentSummaryCard
  shows a one-line note when invoices were excluded; CalendarDayView
  renders each invoice in its own currency instead.
- Deadlines page: the overdue attn sum now skips unconverted FX
  invoices and appends "(+N i utlandsk valuta)" instead of adding EUR
  into a kr total.
- Supplier-invoice payment toast formats the amount with the invoice's
  currency (key drops its hardcoded " kr" in both locales).
- AR aging drill-down row labels Betalt with the invoice currency,
  mirroring the outstanding cell.
- BankFileColumnMappingStep: comment pinning why SEK is safe there
  (generic-csv hardcodes it).

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-25 12:59:14 +02:00

109 lines
4.2 KiB
TypeScript

'use client'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Invoice } from '@/types'
import { calculatePeriodSummary, SWEDISH_MONTHS } from '@/lib/calendar/utils'
import { formatCurrency } from '@/lib/utils'
import { TrendingUp, Clock, CheckCircle, AlertTriangle } from 'lucide-react'
interface PaymentSummaryCardProps {
invoices: Invoice[]
year: number
month: number
}
export function PaymentSummaryCard({ invoices, year, month }: PaymentSummaryCardProps) {
const summary = calculatePeriodSummary(invoices)
return (
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-lg">
Sammanfattning {SWEDISH_MONTHS[month]} {year}
</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
{/* Expected */}
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<div className="h-8 w-8 rounded-lg bg-muted flex items-center justify-center">
<TrendingUp className="h-4 w-4 text-muted-foreground" />
</div>
<div>
<p className="text-sm text-muted-foreground">Förväntat</p>
<p className="text-sm font-medium">{summary.pendingCount} fakturor</p>
</div>
</div>
<p className="text-lg font-semibold">{formatCurrency(summary.totalExpected)}</p>
</div>
{/* Overdue */}
{summary.overdueCount > 0 && (
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<div className="h-8 w-8 rounded-lg bg-muted flex items-center justify-center">
<AlertTriangle className="h-4 w-4 text-muted-foreground" />
</div>
<div>
<p className="text-sm text-muted-foreground">Förfallen</p>
<p className="text-sm font-medium text-destructive">
{summary.overdueCount} fakturor
</p>
</div>
</div>
<p className="text-lg font-semibold text-destructive">
{formatCurrency(summary.totalOverdue)}
</p>
</div>
)}
{/* Paid */}
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<div className="h-8 w-8 rounded-lg bg-muted flex items-center justify-center">
<CheckCircle className="h-4 w-4 text-muted-foreground" />
</div>
<div>
<p className="text-sm text-muted-foreground">Betald</p>
<p className="text-sm font-medium">{summary.paidCount} fakturor</p>
</div>
</div>
<p className="text-lg font-semibold text-success">
{formatCurrency(summary.totalPaid)}
</p>
</div>
{/* Pending */}
{summary.pendingCount > 0 && summary.overdueCount < summary.pendingCount && (
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<div className="h-8 w-8 rounded-lg bg-muted flex items-center justify-center">
<Clock className="h-4 w-4 text-muted-foreground" />
</div>
<div>
<p className="text-sm text-muted-foreground">Väntande</p>
<p className="text-sm font-medium">
{summary.pendingCount - summary.overdueCount} fakturor
</p>
</div>
</div>
<p className="text-lg font-semibold">
{formatCurrency(summary.totalExpected - summary.totalOverdue)}
</p>
</div>
)}
{/* Foreign-currency invoices without a stored SEK conversion are
excluded from the sums above rather than silently mixed in. */}
{summary.unconvertedCount > 0 && (
<p className="text-xs text-warning">
{summary.unconvertedCount === 1
? '1 faktura i utländsk valuta utan växelkurs ingår inte i beloppen.'
: `${summary.unconvertedCount} fakturor i utländsk valuta utan växelkurs ingår inte i beloppen.`}
</p>
)}
</CardContent>
</Card>
)
}