fix(dashboard): include all CAPAs in on-time rate, count open+not-overdue as on-time
This commit is contained in:
@@ -74,9 +74,9 @@ export default async function HseDashboardPage({
|
|||||||
dueDate: capaActions.dueDate,
|
dueDate: capaActions.dueDate,
|
||||||
completedAt: capaActions.completedAt,
|
completedAt: capaActions.completedAt,
|
||||||
verifiedAt: capaActions.verifiedAt,
|
verifiedAt: capaActions.verifiedAt,
|
||||||
|
status: capaActions.status,
|
||||||
})
|
})
|
||||||
.from(capaActions)
|
.from(capaActions)
|
||||||
.where(isNotNull(capaActions.completedAt))
|
|
||||||
),
|
),
|
||||||
asAdmin(db =>
|
asAdmin(db =>
|
||||||
db.select({ id: doshReports.id })
|
db.select({ id: doshReports.id })
|
||||||
@@ -131,16 +131,16 @@ export default async function HseDashboardPage({
|
|||||||
.slice(0, 10)
|
.slice(0, 10)
|
||||||
const zoneMax = by_zone[0]?.count ?? 1
|
const zoneMax = by_zone[0]?.count ?? 1
|
||||||
|
|
||||||
|
const today = now.toISOString().slice(0, 10)
|
||||||
const capas = completedCapas
|
const capas = completedCapas
|
||||||
const onTime = capas.filter(c => {
|
const onTime = capas.filter(c => {
|
||||||
if (!c.dueDate) return false
|
if (!c.dueDate) return true
|
||||||
const due = new Date(c.dueDate)
|
if (c.completedAt) {
|
||||||
const done = c.verifiedAt
|
const done = c.verifiedAt ? new Date(c.verifiedAt) : new Date(c.completedAt)
|
||||||
? new Date(c.verifiedAt)
|
return done <= new Date(c.dueDate)
|
||||||
: c.completedAt
|
}
|
||||||
? new Date(c.completedAt)
|
// Still open — on time if not yet past due
|
||||||
: null
|
return c.dueDate >= today
|
||||||
return done !== null && done <= due
|
|
||||||
})
|
})
|
||||||
const capaOnTimeRate = capas.length > 0
|
const capaOnTimeRate = capas.length > 0
|
||||||
? Math.round((onTime.length / capas.length) * 100)
|
? Math.round((onTime.length / capas.length) * 100)
|
||||||
|
|||||||
Reference in New Issue
Block a user