diff --git a/portal/src/pages/Frequencia.tsx b/portal/src/pages/Frequencia.tsx index b5e8f18..b59dcc5 100644 --- a/portal/src/pages/Frequencia.tsx +++ b/portal/src/pages/Frequencia.tsx @@ -150,24 +150,31 @@ export default function Frequencia() { const lessonStartMs = lessonMs; const lessonEndMs = parseLessonDateTime(lesson.date, lesson.endTime || '00:00:00', lesson.endTime ? 0 : 60); - // No Manager, ele procura o primeiro registro válido - const att = attendance.find(a => { + // Pega todos os registros válidos na janela de tempo + const allAtts = attendance.filter(a => { if (!a.date || typeof a.date !== 'string') return false; - - // 1. Exact Match (Including Manager DB fallback format) if (a.date === `${lesson.date}T${lesson.startTime || '00:00'}:00` || a.date === lessonFullISO) return true; - const attMs = new Date(a.date).getTime(); const presenceStartWindow = lessonStartMs - 30 * 60000; - - // 2. Window Match (Matches Manager Logic: 30 mins before until end of lesson) return attMs >= presenceStartWindow && attMs <= lessonEndMs; }); + // Prioridade de seleção para o status da aula: + // 1. Presença + // 2. Justificativa + // 3. Qualquer outro (Falta/Aguardando) + let bestRecord = allAtts.find(a => a.type === 'presence' || (!a.type && !a.isVirtual) || a.verified === true); + if (!bestRecord) { + bestRecord = allAtts.find(a => !!a.justification); + } + if (!bestRecord && allAtts.length > 0) { + bestRecord = allAtts[0]; + } + const { isInProgress, isCompleted } = getLessonTimeStatus(lesson, now); return { lesson, - attendances: att ? [att] : [], // Simulando o comportamento do manager (apenas 1 registro) + attendances: bestRecord ? [bestRecord] : [], // Mantém 1 registro para alinhar com Manager isInProgress, isCompleted }; @@ -179,18 +186,20 @@ export default function Frequencia() { let justified = 0; processedItems.forEach(item => { - const { lesson, attendances: atts, isCompleted } = item; - if (lesson.status === 'cancelled') return; // Apenas canceladas ficam fora + const { lesson, attendances: atts } = item; + if (lesson.status === 'cancelled') return; - const isPresent = atts.some(a => a.type === 'presence' || a.verified === true); - const activeJustification = atts.find(a => !!a.justification); - const hasJustification = !!activeJustification; + const record = atts[0]; + const lessonEnd = new Date(lesson.date + 'T' + (lesson.endTime || '23:59') + ':00'); - if (isPresent) { - presences++; - } else if (activeJustification?.justificationAccepted) { - justified++; - } else if (isCompleted || parseLessonDateTime(lesson.date || '', '23:59:59') < now.getTime()) { + if (record) { + if (record.type === 'absence') { + if (record.justificationAccepted) justified++; + else absences++; + } else if (record.type === 'presence' || (!record.type && !record.isVirtual) || record.verified) { + presences++; + } + } else if (now > lessonEnd) { absences++; } }); @@ -540,11 +549,11 @@ export default function Frequencia() { Presente ) : isJustificationAccepted ? ( - - Falta Justificada + + Falta Justificada ) : hasJustification ? ( - + Justificativa Pendente ) : (isCompleted || parseLessonDateTime(lesson.date || '', '23:59:59') < now.getTime()) && !isCancelled ? ( @@ -595,7 +604,7 @@ export default function Frequencia() { {justText ? ( - + {isJustificationAccepted ? 'Justificativa Aceita' : 'Em Análise'}