diff --git a/frontend/src/pages/Dashboard.jsx b/frontend/src/pages/Dashboard.jsx index c006d79..03ff6e1 100644 --- a/frontend/src/pages/Dashboard.jsx +++ b/frontend/src/pages/Dashboard.jsx @@ -368,10 +368,12 @@ export default function Dashboard() { 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 missingRank = [...byStaff].sort((a, b) => (b.missing_count || 0) - (a.missing_count || 0)) - const attendanceRate = [...byStaff].map(s => ({ - ...s, - 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 - })).sort((a, b) => b.rate - a.rate) + // Use backend's pre-computed attendance_rate = (total - missing) / total * 100 + // (handles missing records correctly; a record can still be late/early/ot + // and count as attended) + const attendanceRate = [...byStaff] + .map(s => ({ ...s, rate: s.attendance_rate ?? 0 })) + .sort((a, b) => b.rate - a.rate) const statCards = summary ? [ { label: '總記錄', value: summary.total_records, icon: Calendar, color: 'bg-blue-50 text-blue-600' },