Scope dashboard KPIs to Shape clients only
- Client count: Shape/Shape2 designation only - Policy count: active Shape policies (excludes dead statuses) - Task count: open tasks on Shape clients (excludes NA/CANCELLED) - Completion rate: excludes NA/CANCELLED from denominator - /api/metrics intentionally left as system-wide (Prometheus)
This commit is contained in:
parent
c07e02855e
commit
db9dae7c7c
1 changed files with 14 additions and 11 deletions
|
|
@ -14,15 +14,18 @@ export default async function DashboardPage() {
|
|||
redirect('/auth/signin')
|
||||
}
|
||||
|
||||
// Fetch real statistics
|
||||
const [clientCount, policyCount, taskCount] = await Promise.all([
|
||||
prisma.client.count(),
|
||||
prisma.policy.count(),
|
||||
prisma.task.count({ where: { status: { not: 'COMPLETED' } } }),
|
||||
// Fetch real statistics — scoped to Shape clients only
|
||||
const shapeWhere = { designation: { name: { in: ['Shape', 'Shape 2'] } } }
|
||||
const shapeClientIds = (await prisma.client.findMany({ where: shapeWhere, select: { id: true } })).map((c) => c.id)
|
||||
|
||||
const [clientCount, policyCount, taskCount, completedTasks, totalTasks] = await Promise.all([
|
||||
prisma.client.count({ where: shapeWhere }),
|
||||
prisma.policy.count({ where: { clientId: { in: shapeClientIds }, status: { notIn: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] } } }),
|
||||
prisma.task.count({ where: { clientId: { in: shapeClientIds }, status: { notIn: ['COMPLETED', 'CANCELLED', 'NA'] } } }),
|
||||
prisma.task.count({ where: { clientId: { in: shapeClientIds }, status: 'COMPLETED' } }),
|
||||
prisma.task.count({ where: { clientId: { in: shapeClientIds }, status: { notIn: ['CANCELLED', 'NA'] } } }),
|
||||
])
|
||||
|
||||
const completedTasks = await prisma.task.count({ where: { status: 'COMPLETED' } })
|
||||
const totalTasks = await prisma.task.count()
|
||||
const completionRate = totalTasks > 0 ? Math.round((completedTasks / totalTasks) * 100) : 0
|
||||
|
||||
return (
|
||||
|
|
@ -47,7 +50,7 @@ export default async function DashboardPage() {
|
|||
<CardContent>
|
||||
<div className="text-3xl font-bold">{clientCount}</div>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Active client accounts
|
||||
Shape program clients
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
|
@ -60,7 +63,7 @@ export default async function DashboardPage() {
|
|||
<CardContent>
|
||||
<div className="text-3xl font-bold">{policyCount}</div>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Policies requiring renewal
|
||||
Active Shape policies
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
|
@ -73,7 +76,7 @@ export default async function DashboardPage() {
|
|||
<CardContent>
|
||||
<div className="text-3xl font-bold">{taskCount}</div>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Tasks awaiting completion
|
||||
Open tasks (excludes NA/cancelled)
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
|
@ -86,7 +89,7 @@ export default async function DashboardPage() {
|
|||
<CardContent>
|
||||
<div className="text-3xl font-bold">{completionRate}%</div>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Tasks completed on time
|
||||
Tasks completed vs total
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue