1
0
Fork 0
fahrPool/web/lib/auftraege/ProtokollDocument.tsx

115 lines
4.1 KiB
TypeScript

import { Document, Page, Text, View, Image, StyleSheet } from "@react-pdf/renderer";
import type { ProtokollProps } from "./protokoll";
const styles = StyleSheet.create({
page: { padding: 32, fontSize: 11 },
kopf: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", marginBottom: 12 },
logo: { height: 32, maxWidth: 160, objectFit: "contain" },
firmenname: { fontSize: 10 },
h1: { fontSize: 16, marginBottom: 12, fontWeight: 700 },
row: { flexDirection: "row", justifyContent: "space-between", marginBottom: 4 },
fotoGrid: { flexDirection: "row", flexWrap: "wrap", gap: 8, marginTop: 12 },
foto: { width: 120, marginBottom: 8 },
fotoImg: { width: 120, height: 90, objectFit: "cover" },
fotoLabel: { fontSize: 9, marginTop: 2 },
unterschrift: { width: 200, height: 80, marginTop: 8, borderWidth: 1, borderColor: "#ccc" },
});
function formatDatum(iso: string | null): string {
if (iso === null) {
return "-";
}
return new Intl.DateTimeFormat("de-DE", { dateStyle: "medium", timeStyle: "short" }).format(new Date(iso));
}
export function ProtokollDocument({ props }: { props: ProtokollProps }) {
return (
<Document>
<Page size="A4" style={styles.page}>
<View style={styles.kopf}>
{props.firma.logo ? (
<Image style={styles.logo} src={{ data: props.firma.logo.buffer, format: props.firma.logo.format }} />
) : (
<Text style={[styles.firmenname, { color: props.firma.farbe }]}>{props.firma.name}</Text>
)}
{props.firma.logo && <Text style={styles.firmenname}>{props.firma.name}</Text>}
</View>
<Text style={[styles.h1, { color: props.firma.farbe }]}>Übergabeprotokoll {props.auftragsnummer}</Text>
<View style={styles.row}>
<Text>Fahrzeug</Text>
<Text>{props.fahrzeug}</Text>
</View>
{props.fahrzeugFin && (
<View style={styles.row}>
<Text>FIN</Text>
<Text>{props.fahrzeugFin}</Text>
</View>
)}
{props.finAbgleich && (
<View style={styles.row}>
<Text>FIN-Abgleich bei Fahrtbeginn</Text>
<Text>{props.finAbgleich}</Text>
</View>
)}
<View style={styles.row}>
<Text>Abholort</Text>
<Text>
{props.abholort.adresse} ({props.abholort.ansprechpartner})
</Text>
</View>
<View style={styles.row}>
<Text>Zielort</Text>
<Text>
{props.zielort.adresse} ({props.zielort.ansprechpartner})
</Text>
</View>
<View style={styles.row}>
<Text>Fahrer</Text>
<Text>{props.fahrerName ?? "-"}</Text>
</View>
<View style={styles.row}>
<Text>Startzeit</Text>
<Text>{formatDatum(props.startZeit)}</Text>
</View>
<View style={styles.row}>
<Text>Start-KM</Text>
<Text>{props.startKm ?? "-"}</Text>
</View>
<View style={styles.row}>
<Text>End-KM</Text>
<Text>{props.endKm ?? "-"}</Text>
</View>
<View style={styles.row}>
<Text>Übergabe bestätigt</Text>
<Text>{formatDatum(props.uebergabeBestaetigtAt)}</Text>
</View>
<View style={styles.row}>
<Text>Empfänger</Text>
<Text>{props.empfaengerName ?? "-"}</Text>
</View>
{props.fotos.length > 0 && (
<View style={styles.fotoGrid}>
{props.fotos.map((foto, index) => (
<View key={index} style={styles.foto}>
<Image src={{ data: foto.buffer, format: foto.format }} style={styles.fotoImg} />
<Text style={styles.fotoLabel}>
{foto.label}
{foto.beschreibung ? `: ${foto.beschreibung}` : ""}
</Text>
</View>
))}
</View>
)}
{props.unterschriftBuffer && (
<>
<Text style={{ marginTop: 12 }}>Unterschrift</Text>
<Image src={{ data: props.unterschriftBuffer, format: "png" }} style={styles.unterschrift} />
</>
)}
</Page>
</Document>
);
}