import { useMemo, useState } from 'react' import { BadgeEuro, CalendarDays, CircleCheck, CircleAlert, Clock, Download, ReceiptText, } from 'lucide-react' import { Badge } from '@/components/ui/badge' import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { useStore, fmtEUR } from '../store/store' const statusStyle: Record = { bezahlt: 'bg-emerald-100 text-emerald-800', offen: 'bg-amber-100 text-amber-800', 'überfällig': 'bg-red-100 text-red-700', } function TenantPayments() { const { meineEinheit: demoUnit, transactions } = useStore() const myTx = useMemo( () => transactions .filter((t) => t.unitId === demoUnit.id) .slice() .reverse(), [transactions, demoUnit], ) const [filter, setFilter] = useState('alle') const rows = filter === 'alle' ? myTx : myTx.filter((t) => t.status === filter) const openSum = myTx.filter((t) => t.status !== 'bezahlt').reduce((s, t) => s + t.amount, 0) const nk2025 = 86.4 // Guthaben laut Abrechnung return (

Mietkonto & Zahlungen

{demoUnit.building} · Whg. {demoUnit.number} – alle Buchungen auf einen Blick

Fällig am 03.10.2026
{fmtEUR.format(demoUnit.warmRent)}
Warmmiete Oktober (überwiesen ausstehend)
Offen gesamt
0 ? 'text-amber-600' : ''}`}> {fmtEUR.format(openSum)}
{myTx.filter((t) => t.status !== 'bezahlt').length} offene Posten
Nebenkosten 2025
+ {fmtEUR.format(nk2025)} Guthaben
Ausgeglichen mit der Oktober-Miete

Buchungsverlauf 2026

Alle Bezahlt Offen Überfällig
Monat Vorgang Betrag Status Beleg {rows.map((t) => ( {t.month} {t.year} {t.type} {fmtEUR.format(t.amount)} {t.status === 'bezahlt' && } {t.status === 'überfällig' && } {t.status} {t.status === 'bezahlt' && ( )} ))}
Zahlungsdaten: IBAN DE44 5001 0517 5407 3249 31 · Verwendungszweck: „Miete {demoUnit.number}/HS 10-2026“ · Zahlungsziel jeweils bis zum 3. des Monats.
) } function AdminPayments() { const { units, transactions } = useStore() const [building, setBuilding] = useState('alle') const list = units .filter((u) => u.status === 'vermietet') .filter((u) => building === 'alle' || u.building === building) .map((u) => { const tx = transactions.filter((t) => t.unitId === u.id) const overdue = tx.filter((t) => t.status === 'überfällig') const lastPaid = tx.filter((t) => t.status === 'bezahlt').slice(-1)[0] return { unit: u, overdue, lastPaid } }) const totals = { soll: list.reduce((s, r) => s + r.unit.warmRent, 0), rueckstand: list.reduce((s, r) => s + r.overdue.reduce((a, t) => a + t.amount, 0), 0), } return (

Mietkonto & Zahlungen

Forderungsmanagement für 50 Wohnungen

Monatlicher Miet-Soll
{fmtEUR.format(totals.soll)}
Gesamtrückstand (überfällig)
0 ? 'text-red-600' : ''}`}> {fmtEUR.format(totals.rueckstand)}

Zahlungsstatus der Mieter

Wohnung Mieter Warmmiete Letzte Zahlung Rückstand Status {list.map(({ unit, overdue, lastPaid }) => ( {unit.building}, Whg. {unit.number} {unit.tenant} {fmtEUR.format(unit.warmRent)} {lastPaid ? `${lastPaid.month} (${lastPaid.paidAt})` : '–'} {overdue.length ? fmtEUR.format(overdue.reduce((a, t) => a + t.amount, 0)) : '–'} {overdue.length ? 'Mahnung prüfen' : 'im Soll'} ))}
) } export default function Payments() { const { role } = useStore() return role === 'tenant' ? : }