import Link from 'next/link'; import { Landmark, FileText, Euro, ArrowRight } from 'lucide-react'; import { getSupabaseServerClient } from '@kit/supabase/server-client'; import { Badge } from '@kit/ui/badge'; import { Button } from '@kit/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@kit/ui/card'; import { createFinanceApi } from '@kit/finance/api'; import { CmsPageShell } from '~/components/cms-page-shell'; import { EmptyState } from '~/components/empty-state'; import { StatsCard } from '~/components/stats-card'; interface PageProps { params: Promise<{ account: string }>; } const BATCH_STATUS_VARIANT: Record< string, 'secondary' | 'default' | 'info' | 'outline' | 'destructive' > = { draft: 'secondary', ready: 'default', submitted: 'info', completed: 'outline', failed: 'destructive', }; const BATCH_STATUS_LABEL: Record = { draft: 'Entwurf', ready: 'Bereit', submitted: 'Eingereicht', completed: 'Abgeschlossen', failed: 'Fehlgeschlagen', }; const INVOICE_STATUS_VARIANT: Record< string, 'secondary' | 'default' | 'info' | 'outline' | 'destructive' > = { draft: 'secondary', sent: 'default', paid: 'info', overdue: 'destructive', cancelled: 'destructive', }; const INVOICE_STATUS_LABEL: Record = { draft: 'Entwurf', sent: 'Versendet', paid: 'Bezahlt', overdue: 'Überfällig', cancelled: 'Storniert', }; export default async function FinancePage({ params }: PageProps) { const { account } = await params; const client = getSupabaseServerClient(); const { data: acct } = await client .from('accounts') .select('id') .eq('slug', account) .single(); if (!acct) return
Konto nicht gefunden
; const api = createFinanceApi(client); const [batches, invoices] = await Promise.all([ api.listBatches(acct.id), api.listInvoices(acct.id), ]); const openAmount = invoices .filter( (inv: Record) => inv.status === 'sent' || inv.status === 'overdue', ) .reduce( (sum: number, inv: Record) => sum + (Number(inv.total_amount) || 0), 0, ); return (
{/* Header */}

Finanzen

SEPA-Einzüge und Rechnungen

{/* Stats */}
} /> } /> } />
{/* SEPA Batches */} Letzte SEPA-Einzüge {batches.length === 0 ? ( } title="Keine SEPA-Einzüge" description="Erstellen Sie Ihren ersten SEPA-Einzug." actionLabel="Neuer SEPA-Einzug" actionHref={`/home/${account}/finance/sepa/new`} /> ) : (
{batches.slice(0, 5).map((batch: Record) => ( ))}
Status Typ Betrag Datum
{BATCH_STATUS_LABEL[String(batch.status)] ?? String(batch.status)} {batch.batch_type === 'direct_debit' ? 'Lastschrift' : 'Überweisung'} {batch.total_amount != null ? `${Number(batch.total_amount).toFixed(2)} €` : '—'} {batch.execution_date ? new Date(String(batch.execution_date)).toLocaleDateString('de-DE') : batch.created_at ? new Date(String(batch.created_at)).toLocaleDateString('de-DE') : '—'}
)}
{/* Invoices */} Letzte Rechnungen {invoices.length === 0 ? ( } title="Keine Rechnungen" description="Erstellen Sie Ihre erste Rechnung." actionLabel="Neue Rechnung" actionHref={`/home/${account}/finance/invoices/new`} /> ) : (
{invoices.slice(0, 5).map((invoice: Record) => ( ))}
Nr. Empfänger Betrag Status
{String(invoice.invoice_number ?? '—')} {String(invoice.recipient_name ?? '—')} {invoice.total_amount != null ? `${Number(invoice.total_amount).toFixed(2)} €` : '—'} {INVOICE_STATUS_LABEL[String(invoice.status)] ?? String(invoice.status)}
)}
); }