'use client' import { useTranslations } from 'next-intl' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, } from '@/components/ui/dialog' import { formatCurrency, formatDate } from '@/lib/utils' import { Loader2 } from 'lucide-react' import type { TransactionWithInvoice } from './transaction-types' interface ExpensePayoutMatchDialogProps { open: boolean onOpenChange: (open: boolean) => void /** Row carrying `potential_expense_payout`; the dialog renders nothing without it. */ transaction: TransactionWithInvoice | null isConfirming: boolean onConfirm: () => void } /** * Confirm dialog for booking an outgoing bank row as the repayment of one * person's registered utlägg: the person's liability account is debited, * the row's cash account credited, the claims flip to paid and the row is * linked to the voucher, all in one RPC call. Two legs, amount from the bank * row, so everything to approve is known up front (convention 10). */ export default function ExpensePayoutMatchDialog({ open, onOpenChange, transaction, isConfirming, onConfirm, }: ExpensePayoutMatchDialogProps) { const t = useTranslations('tx_expense_payout_match') const match = transaction?.potential_expense_payout ?? null const currency = transaction?.currency || 'SEK' const amount = transaction ? Math.abs(transaction.amount) : 0 return ( {t('title')} {t('description')} {transaction && match && (

{transaction.description}

{formatDate(transaction.date)} {formatCurrency(-amount, currency)}

{match.claimant_name}

{match.claim_count === 1 ? t('claims_one', { date: formatDate(match.oldest_expense_date) }) : t('claims_other', { count: match.claim_count, date: formatDate(match.oldest_expense_date) })}

{match.liability_account} D {formatCurrency(amount, 'SEK')} · 19xx K {formatCurrency(amount, 'SEK')}

{t('outcome')}

)}
) }