import Link from 'next/link'; import { Landmark, FileText, Euro, ArrowRight, Plus } 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'; import { AccountNotFound } from '~/components/account-not-found'; import { BATCH_STATUS_VARIANT, BATCH_STATUS_LABEL, INVOICE_STATUS_VARIANT, INVOICE_STATUS_LABEL, } from '~/lib/status-badges'; interface PageProps { params: Promise<{ account: string }>; } 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 ; 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.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.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)}
)}
); }