fix(dashboard): use backend attendance_rate instead of broken client formula
Old formula: (total - late - abnormal) / total - Did not subtract missing (so 100% with 缺勤 2) - Subtracted abnormal twice (already hidden late/early/ot) - Could never reach 0% New: read backend's pre-computed attendance_rate = (total - missing) / total * 100 Wing Fung (10 rec, 2 missing) now 80% (was 100%) Cindy (10 rec, 4 missing) now 60% (was 90%)
This commit is contained in:
@@ -368,10 +368,12 @@ export default function Dashboard() {
|
|||||||
const otRank = [...byStaff].sort((a, b) => (b.ot_count || 0) - (a.ot_count || 0))
|
const otRank = [...byStaff].sort((a, b) => (b.ot_count || 0) - (a.ot_count || 0))
|
||||||
const abnormalRank = [...byStaff].sort((a, b) => (b.abnormal_count || 0) - (a.abnormal_count || 0))
|
const abnormalRank = [...byStaff].sort((a, b) => (b.abnormal_count || 0) - (a.abnormal_count || 0))
|
||||||
const missingRank = [...byStaff].sort((a, b) => (b.missing_count || 0) - (a.missing_count || 0))
|
const missingRank = [...byStaff].sort((a, b) => (b.missing_count || 0) - (a.missing_count || 0))
|
||||||
const attendanceRate = [...byStaff].map(s => ({
|
// Use backend's pre-computed attendance_rate = (total - missing) / total * 100
|
||||||
...s,
|
// (handles missing records correctly; a record can still be late/early/ot
|
||||||
rate: (s.total_records || s.total || 0) > 0 ? Math.round(((((s.total_records || s.total || 0) - (s.late_count || 0) - (s.abnormal_count || 0))) / (s.total_records || s.total || 0)) * 100) : 0
|
// and count as attended)
|
||||||
})).sort((a, b) => b.rate - a.rate)
|
const attendanceRate = [...byStaff]
|
||||||
|
.map(s => ({ ...s, rate: s.attendance_rate ?? 0 }))
|
||||||
|
.sort((a, b) => b.rate - a.rate)
|
||||||
|
|
||||||
const statCards = summary ? [
|
const statCards = summary ? [
|
||||||
{ label: '總記錄', value: summary.total_records, icon: Calendar, color: 'bg-blue-50 text-blue-600' },
|
{ label: '總記錄', value: summary.total_records, icon: Calendar, color: 'bg-blue-50 text-blue-600' },
|
||||||
|
|||||||
Reference in New Issue
Block a user