import type { Metadata } from 'next' import { db } from '@/lib/db' import { loadDocumentSections } from '@/lib/documents/service' import { loadVisibleDocument } from '@/lib/documents/service' import { resolvePhotoUrls } from '@/lib/files/service' import { permissionsForPrint } from '@/lib/export/printAccess' import { Sheet } from '@/components/documents/Sheet' import { de } from '@/lib/i18n/de' import { NotAvailable } from '../../../NotAvailable' import { isInputField, fillPlaceholders } from '@/lib/templates/fields' export const dynamic = 'force-dynamic' export async function generateMetadata({ params, }: { params: Promise<{ documentNumber: string }> }): Promise { const { documentNumber } = await params return { title: documentNumber, robots: { index: false, follow: false } } } /** * Druckansicht eines einzelnen Dokuments. * * Kein Verlauf, keine Kopfdatentabelle einer Akte - das Dokument selbst, so * wie seine Vorlage es vorsieht. Ein Aktenblatt kommt als Aktenblatt heraus, * ein Vertrag als Vertrag. Siehe docs/08-suche-und-export.md. */ export default async function PrintDocumentPage({ params, searchParams, }: { params: Promise<{ documentNumber: string }> searchParams: Promise<{ token?: string }> }) { const { documentNumber } = await params const { token } = await searchParams const zugang = await permissionsForPrint(token) if (!zugang) return const { permissions, displayName } = zugang const doc = await loadVisibleDocument(permissions, documentNumber) if (!doc) return const [sections, template, foundationLevels, levels] = await Promise.all([ loadDocumentSections(permissions, doc), db.documentTemplate.findUnique({ where: { id: doc.templateId }, select: { sheetTitle: true, sheetSubtitle: true, name: true }, }), db.foundationClearance.findMany({ orderBy: { sortOrder: 'asc' } }), db.clearanceLevelConfig.findMany({ orderBy: { level: 'asc' } }), ]) const photoUrls = await resolvePhotoUrls( permissions, sections.map((section) => ({ fieldKey: section.fieldKey, visible: section.visible, value: section.visible ? section.value : null, type: section.field.type, })), ) const levelName = new Map(levels.map((l) => [l.level, l.name])) const werte = Object.fromEntries( sections.filter((s) => s.visible).map((s) => [s.fieldKey, s.value]), ) // Das Aktenblatt bringt sein eigenes Aussehen mit und braucht keinen // Berichtsrahmen darum. if (doc.layout === 'DOSSIER') { return ( ) } return (
{doc.classification} · {levelName.get(doc.classification) ?? de.common.unknown}

{doc.title}

{doc.documentNumber}

{de.case.status} {de.document.statusNames[doc.status] ?? doc.status}
{de.document.kind} {doc.templateKey}
{de.export.retrievedBy} {displayName}
{de.export.asOf} {new Date().toLocaleString('de-DE')} · {de.clearance.label}{' '} {permissions.clearanceLevel}
{doc.retractedAt ? (

{de.document.statusNames.RETRACTED}

) : null} {sections.map((section) => { const field = section.field if (!isInputField(field)) { if (field.type === 'pagebreak') { return
} const text = fillPlaceholders(field.text ?? '', werte) return field.type === 'heading' ? (

{text || field.label}

) : (

{text}

) } if (field.type === 'signature') { return (

{fillPlaceholders(field.label, werte)}

) } return (

{field.label}

{!section.visible ? (

 {' '} {de.export.redactedAt( section.value.requiredLevel, levelName.get(section.value.requiredLevel) ?? '', )}

) : (

{String(section.value ?? '-')}

)}
) })}
) }