'use client' import Link from 'next/link' import { Badge } from '@/components/ui/badge' import { Info } from 'lucide-react' import JournalEntryStatusBadge from '@/components/bookkeeping/JournalEntryStatusBadge' import type { JournalEntry, JournalEntryLine } from '@/types' interface Props { currentEntryId: string chain: JournalEntry[] } function getRole(entry: JournalEntry): { label: string; color: string } { if (entry.source_type === 'storno') { return { label: 'Storno', color: 'bg-destructive' } } if (entry.source_type === 'correction') { return { label: 'Rättelse', color: 'bg-primary' } } return { label: 'Original', color: 'bg-muted-foreground' } } function getTotal(entry: JournalEntry): number { const lines = (entry.lines || []) as JournalEntryLine[] return lines.reduce((sum, l) => sum + (Number(l.debit_amount) || 0), 0) } export default function CorrectionChain({ currentEntryId, chain }: Props) { if (chain.length === 0) return null // Combine current entry isn't in chain — chain is "other" entries // Sort chronologically const sorted = [...chain].sort( (a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime() ) return (

Ändringskedja

Bokförda verifikationer kan inte ändras direkt. Istället skapas en stornoverifikation som nollställer den ursprungliga, och en ny rättelsepost med de korrekta uppgifterna.

{/* Vertical line connecting nodes */}
{sorted.map((entry) => { const role = getRole(entry) const total = getTotal(entry) const isCurrent = entry.id === currentEntryId return (
{/* Timeline dot */}
{role.label} {entry.voucher_series}{entry.voucher_number} {entry.entry_date} {isCurrent && ( Aktuell )} {total.toLocaleString('sv-SE', { minimumFractionDigits: 2 })} kr
{entry.description && (

{entry.description}

)}
) })}
) }