import { PrintChart } from "@/components/orgchart/PrintChart"; import type { OrgUnitNode } from "@/components/orgchart/types"; import { currentUserId } from "@/lib/auth/session"; import { withUser } from "@/lib/db"; import { todayIso } from "@/lib/format"; import { loadOrgAsOf } from "@/lib/orgchart-data"; import { buildPrintModel } from "@/lib/orgchart-print"; import { parseIsoDateParam } from "@/lib/reports"; export const metadata = { title: "Organigramm drucken" }; type SearchParams = { asOf?: string }; // Eigene Route statt eines Druckstils auf der Organigramm-Seite. // // Die interaktive Ansicht ist eine Leinwand mit Zoom und Verschiebung; was // davon auf Papier landet, hängt vom Zufallsstand der Ansicht ab. Hier wird // stattdessen aus denselben Daten eine Seitenfolge gebaut, und der Stichtag // wird aus der Adresse übernommen — wer im Organigramm einen Stichtag // eingestellt hat, druckt genau den. export default async function OrgChartPrintPage({ searchParams }: { searchParams: Promise }) { const params = await searchParams; const today = todayIso(); const asOf = parseIsoDateParam(params.asOf) ?? today; const { org, units } = await withUser(await currentUserId(), async (tx) => { const [org, units] = await Promise.all([ loadOrgAsOf(tx, asOf), tx .selectFrom("org_units") .select(["id", "org_number", "name", "parent_id", "unit_type"]) .where((eb) => eb.or([eb("valid_to", "is", null), eb("valid_to", ">", asOf)])) .where("valid_from", "<=", asOf) .orderBy("org_number") .execute(), ]); return { org, units }; }); const model = buildPrintModel(units as OrgUnitNode[], org.employees, org.vacancies); return ; }