feat: add buildPdf for cashbox export

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Bastian Wagner
2026-08-03 21:20:57 +02:00
parent 0b408f7d73
commit f8857f71e1
2 changed files with 58 additions and 1 deletions

View File

@@ -1,4 +1,6 @@
import { Team } from 'src/teams/entities/team.entity';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const PDFDocument = require('pdfkit');
export interface CashboxExportRow {
date: string;
@@ -100,3 +102,35 @@ export function buildCsv(rows: CashboxExportRow[]): string {
}
return lines.join('\r\n');
}
export function buildPdf(
team: Pick<Team, 'name'>,
rows: CashboxExportRow[],
from: string,
to: string,
): Promise<Buffer> {
return new Promise((resolve, reject) => {
const doc = new PDFDocument({ margin: 40 });
const chunks: Buffer[] = [];
doc.on('data', (chunk) => chunks.push(chunk));
doc.on('end', () => resolve(Buffer.concat(chunks)));
doc.on('error', reject);
doc.fontSize(16).text(`Kassenbuch ${team.name}`);
doc.fontSize(10).text(`Zeitraum: ${from} bis ${to}`);
doc.moveDown();
if (rows.length === 0) {
doc.text('Keine Buchungen im gewählten Zeitraum.');
} else {
for (const row of rows) {
doc.text(
`${row.date.slice(0, 10)} ${TYPE_LABELS[row.type] ?? row.type} ${row.who} ${row.note} ` +
`${formatGermanAmount(row.amount)} € Saldo: ${formatGermanAmount(row.runningTotal)}`,
);
}
}
doc.end();
});
}