'use client' import { Badge } from '@/components/ui/badge' import { Separator } from '@/components/ui/separator' import { formatCurrency } from '@/lib/utils' import type { Customer, Currency } from '@/types' interface ReviewItem { description: string quantity: number unit: string unit_price: number vat_rate?: number } interface InvoiceReviewContentProps { customer: Customer invoiceDate: string dueDate: string currency: Currency items: ReviewItem[] subtotal: number vatAmount: number total: number yourReference?: string ourReference?: string notes?: string } export function InvoiceReviewContent({ customer, invoiceDate, dueDate, currency, items, subtotal, vatAmount, total, yourReference, ourReference, notes, }: InvoiceReviewContentProps) { const customerTypeLabel: Record = { individual: 'Privatperson', swedish_business: 'Svenskt företag', eu_business: 'EU-företag', non_eu_business: 'Utanför EU', } // Calculate per-rate VAT breakdown const vatByRate = new Map() for (const item of items) { const rate = item.vat_rate ?? 0 const lineTotal = item.quantity * item.unit_price const lineVat = Math.round(lineTotal * rate / 100 * 100) / 100 vatByRate.set(rate, (vatByRate.get(rate) || 0) + lineVat) } const showVatColumn = vatByRate.size > 1 return (
{/* Customer info */}

{customer.name}

{customer.email}

{customerTypeLabel[customer.customer_type] || customer.customer_type}
{/* Dates */}
Fakturadatum

{invoiceDate}

Förfallodatum

{dueDate}

{/* Line items table */} {showVatColumn && } {items.map((item, index) => ( {showVatColumn && ( )} ))}
Beskrivning Antal Enhet À-prisMomsBelopp
{item.description} {item.quantity} {item.unit} {formatCurrency(item.unit_price, currency)}{item.vat_rate ?? 0}% {formatCurrency(item.quantity * item.unit_price, currency)}
{/* Totals */}
Delsumma {formatCurrency(subtotal, currency)}
{Array.from(vatByRate.entries()) .filter(([, vat]) => vat > 0) .sort(([a], [b]) => b - a) .map(([rate, vat]) => (
Moms {rate}% {formatCurrency(vat, currency)}
))} {Array.from(vatByRate.values()).every((vat) => vat === 0) && (
Moms {formatCurrency(0, currency)}
)}
Totalt {formatCurrency(total, currency)}
{/* References/notes */} {(yourReference || ourReference || notes) && (
{yourReference &&

Er referens: {yourReference}

} {ourReference &&

Vår referens: {ourReference}

} {notes &&

Anteckning: {notes}

}
)}
) }