import React from "react"; import { PROTOKOLL_TYPES } from "../constants.js"; import { formatDate } from "../utils.js"; import { Header } from "../components/UI.jsx"; export default function Documents({ data, setView }) { const protocols = (data.protocols || []).sort((a, b) => (b.date || "").localeCompare(a.date || "")); const deliveryNotes = (data.deliveryNotes || []).sort((a, b) => (b.date || "").localeCompare(a.date || "")); const letterTemplates = data.letterTemplates || []; const recentProtos = protocols.slice(0, 6); const recentNotes = deliveryNotes.slice(0, 5); const protoByType = PROTOKOLL_TYPES.map(t => ({ type: t, count: protocols.filter(p => p.type === t).length, })).filter(r => r.count > 0).sort((a, b) => b.count - a.count); const maxTypeCount = protoByType[0]?.count || 1; const getClient = (n) => { if (n.clientId) return (data.persons||[]).filter(p=>p.isAuftraggeber).find(c => c.id === n.clientId)?.name || "—"; if (n.projectId) { const proj = data.projects?.find(p => p.id === n.projectId); if (proj?.clientId) return (data.persons||[]).filter(p=>p.isAuftraggeber).find(c => c.id === proj.clientId)?.name || "—"; } return "—"; }; const getProject = (n) => { if (!n.projectId) return null; return data.projects?.find(p => p.id === n.projectId)?.name || null; }; const SectionCard = ({ title, count, action, onAction, children, accent }) => (
| Datum | Typ | Titel | Projekt | Einträge |
|---|---|---|---|---|
| {formatDate(p.date)} | {p.type || "—"} | {p.title || —} | {proj || —} | {(p.entries || []).length} |
| Nr. | Datum | Kunde | Projekt | Positionen |
|---|---|---|---|---|
| {n.number || "—"} | {formatDate(n.date)} | {getClient(n)} | {getProject(n) || —} | {(n.items || []).length} |