feat(export): CSV- und PDF-Ausgaben fuer Hosts, Kunden und Rechnungen (#010)

PDFs entstehen serverseitig mit @react-pdf/renderer, mit einfarbigem Logo,
wiederholtem Spaltenkopf und Summenzeile. Alle Exporte uebernehmen die Filter
der jeweiligen Ansicht.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-17 22:12:58 +02:00
co-authored by Claude Opus 5
parent 6168ad69f2
commit cb009efd7d
15 changed files with 1093 additions and 51 deletions
+40 -2
View File
@@ -1,7 +1,11 @@
import { PRODUKT_TEXT, STATUS_TEXT, statusAusDatenbank } from "@/lib/anzeige";
import { csvAntwort, csvDatei } from "@/lib/csv";
import { formatDatum } from "@/lib/format";
import { Bericht, pdfAntwort, Tabelle } from "@/server/pdf/dokument";
import { hostListe, type HostFilter } from "@/server/queries/hostliste";
type ExportHost = Awaited<ReturnType<typeof hostListe>>["hosts"][number];
export const dynamic = "force-dynamic";
/** CSV-Export der Host-Tabelle; übernimmt die Filter aus der Adresse. */
@@ -20,13 +24,48 @@ export async function GET(request: Request) {
};
const { gesamt } = await hostListe({ ...filter }, new Date());
const alle = [];
const alle: ExportHost[] = [];
for (let seite = 1; alle.length < gesamt; seite++) {
const teil = await hostListe({ ...filter, seite }, new Date());
if (teil.hosts.length === 0) break;
alle.push(...teil.hosts);
}
const datum = new Date().toISOString().slice(0, 10);
if (new URL(request.url).searchParams.get("format") === "pdf") {
return pdfAntwort(
Bericht({
titel: "Host-Liste",
untertitel: `${alle.length} Hosts`,
quer: true,
children: Tabelle({
spalten: [
{ titel: "Host", breite: 18, wert: (h: ExportHost) => h.hostname },
{ titel: "Kunde", breite: 18, wert: (h) => h.kunde?.name ?? "Nicht zugeordnet" },
{ titel: "Produkt", breite: 15, wert: (h) => PRODUKT_TEXT[h.produkt] },
{ titel: "Status", breite: 12, wert: (h) => STATUS_TEXT[statusAusDatenbank(h.subStatus)] },
{ titel: "Key", breite: 15, wert: (h) => h.subKey ?? "–" },
{
titel: "Sockets",
breite: 8,
wert: (h) => `${h.subLizenzierteSockets ?? "–"} / ${h.sockets ?? "–"}`,
rechts: true,
},
{
titel: "Ablauf",
breite: 14,
wert: (h) => (h.subNextduedate ? formatDatum(h.subNextduedate) : "–"),
rechts: true,
},
],
zeilen: alle,
}),
}),
`proxledger-hosts-${datum}.pdf`,
);
}
const inhalt = csvDatei(
[
"Hostname",
@@ -64,6 +103,5 @@ export async function GET(request: Request) {
]),
);
const datum = new Date().toISOString().slice(0, 10);
return csvAntwort(inhalt, `proxledger-hosts-${datum}.csv`);
}