feat: add buildReceivableRows for fine/levy/fee entries

Cashbox export previously only saw payment transactions. This adds
the query for fine/levy/fee entries (Forderungen) that the redesigned
PDF report will show in a separate section.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Bastian Wagner
2026-08-04 10:22:59 +02:00
parent 0bad154971
commit 7b499b361f
2 changed files with 121 additions and 1 deletions

View File

@@ -62,10 +62,49 @@ export function buildRows(team: Team, from: string, to: string): CashboxExportRo
});
}
export interface CashboxReceivableRow {
date: string;
type: string;
who: string;
note: string;
amount: number;
}
const RECEIVABLE_TYPES = new Set(['fine', 'levy', 'fee']);
export function buildReceivableRows(team: Team, from: string, to: string): CashboxReceivableRow[] {
const fromTime = new Date(`${from}T00:00:00.000Z`).getTime();
const toTime = new Date(`${to}T23:59:59.999Z`).getTime();
const raw: CashboxReceivableRow[] = [];
for (const player of team.players ?? []) {
for (const transaction of player.transactions ?? []) {
if (!transaction.type || !RECEIVABLE_TYPES.has(transaction.type.name)) continue;
raw.push({
date: transaction.date,
type: transaction.type.name,
who: `${player.firstName} ${player.lastName}`,
note: transaction.note,
amount: Number(transaction.amount),
});
}
}
return raw
.filter((row) => {
const time = new Date(row.date).getTime();
return time >= fromTime && time <= toTime;
})
.sort((a, b) => (a.date < b.date ? -1 : a.date > b.date ? 1 : 0));
}
const TYPE_LABELS: Record<string, string> = {
payment: 'Zahlung',
credit: 'Guthaben',
expense: 'Ausgabe',
fine: 'Strafe',
levy: 'Umlage',
fee: 'Gebühr',
};
function formatGermanAmount(value: number): string {