import React, { useRef, useLayoutEffect } from 'react'; import { format, min, max, isValid } from 'date-fns'; import type { Project, Inspection } from '../../types'; import '../../styles/reports.css'; interface GeneralProjectReportProps { projects: Project[]; inspections?: Inspection[]; title: string; logoUrl?: string; } const ProgressFill: React.FC<{ progress: number }> = ({ progress }) => { const fillRef = useRef(null); useLayoutEffect(() => { if (fillRef.current) { fillRef.current.style.setProperty('--progress', `${progress}%`); } }, [progress]); return
; }; export const GeneralProjectReport: React.FC = ({ projects, inspections = [], title, logoUrl }) => { // Cálculos globais const totalWeight = projects.reduce((acc, p) => acc + (p.weightKg || 0), 0); const calculateProjectProgress = (project: Project) => { const projectInspections = inspections.filter(i => i.projectId === project.id); const sumWeight = projectInspections.reduce((acc, curr) => acc + (curr.weightKg || 0), 0); const totalW = project.weightKg || 0; return totalW > 0 ? Math.min((sumWeight / totalW) * 100, 100) : 0; }; const avgProgress = projects.length > 0 ? projects.reduce((acc, p) => acc + calculateProjectProgress(p), 0) / projects.length : 0; // Período (Min/Max das datas) const allDates = projects.flatMap(p => [ p.startDate ? new Date(p.startDate) : null, p.endDate ? new Date(p.endDate) : null ]).filter((d): d is Date => d !== null && isValid(d)); const periodStart = allDates.length > 0 ? format(min(allDates), 'MM/yyyy') : '--/----'; const periodEnd = allDates.length > 0 ? format(max(allDates), 'MM/yyyy') : '--/----'; return (
{logoUrl ? ( Logo ) : (
)}
{title.toUpperCase()}
Obras / Projetos – Situação de produção e pintura
Data: {format(new Date(), 'dd/MM/yyyy')}
Responsável: ________________
Total de obras
{projects.length}
Listadas neste relatório
Peso total (kgf)
{totalWeight.toLocaleString('pt-BR')}
Soma dos projetos
Evolução média
{avgProgress.toFixed(1).replace('.', ',')}%
Estimativa geral
Período
{periodStart} – {periodEnd}
Previsão de execução

OBRAS / PROJETOS

Visão geral por cronograma, peso e sistema de pintura
{projects.map((project) => { const progress = calculateProjectProgress(project); const schemes = project.paintingSchemes || []; return ( ); })}
Obra / Projeto Evol. Cronograma Peso (kgf) Tinta Cor
{project.name.toUpperCase()}
Cliente: {project.client}
Gestor: {project.technician || '--'}
{Math.round(progress)}%
Início: {project.startDate ? format(new Date(project.startDate), 'dd/MM/yyyy') : '--/--/----'}
Término: {project.endDate ? format(new Date(project.endDate), 'dd/MM/yyyy') : '--/--/----'}
{(project.weightKg || 0).toLocaleString('pt-BR')} Est. total
{schemes.length > 0 ? schemes.slice(0, 2).map((s, idx) => ( {s.name.toUpperCase()} {s.coat || s.type || 'Esquema'}{idx < schemes.length - 1 &&
}
)) : Sem esquema}
{schemes.length > 0 ? schemes.slice(0, 2).map((s, idx) => (
{s.color || '-'}
)) : '-'}
); };