diff --git a/app/(protected)/hse/dashboard/page.tsx b/app/(protected)/hse/dashboard/page.tsx index ebfa4cb..a5e305b 100644 --- a/app/(protected)/hse/dashboard/page.tsx +++ b/app/(protected)/hse/dashboard/page.tsx @@ -74,9 +74,9 @@ export default async function HseDashboardPage({ dueDate: capaActions.dueDate, completedAt: capaActions.completedAt, verifiedAt: capaActions.verifiedAt, + status: capaActions.status, }) .from(capaActions) - .where(isNotNull(capaActions.completedAt)) ), asAdmin(db => db.select({ id: doshReports.id }) @@ -131,16 +131,16 @@ export default async function HseDashboardPage({ .slice(0, 10) const zoneMax = by_zone[0]?.count ?? 1 + const today = now.toISOString().slice(0, 10) const capas = completedCapas const onTime = capas.filter(c => { - if (!c.dueDate) return false - const due = new Date(c.dueDate) - const done = c.verifiedAt - ? new Date(c.verifiedAt) - : c.completedAt - ? new Date(c.completedAt) - : null - return done !== null && done <= due + if (!c.dueDate) return true + if (c.completedAt) { + const done = c.verifiedAt ? new Date(c.verifiedAt) : new Date(c.completedAt) + return done <= new Date(c.dueDate) + } + // Still open — on time if not yet past due + return c.dueDate >= today }) const capaOnTimeRate = capas.length > 0 ? Math.round((onTime.length / capas.length) * 100)