mirror of
https://git.coastit.co.za/caitlin/CRM_ENVR.git
synced 2026-07-10 11:15:43 +02:00
added update from code pull new changes now
This commit is contained in:
@@ -38,6 +38,40 @@ export function getDashboardStats(period: string): DashboardStats {
|
||||
]
|
||||
}
|
||||
|
||||
const monthlyBreakdown = groupLeadsByInterval(filtered, period).map(m => ({
|
||||
label: m.label,
|
||||
total: m.leads,
|
||||
open: 0,
|
||||
contacted: 0,
|
||||
pending: 0,
|
||||
closed: m.closed,
|
||||
ignored: 0,
|
||||
}))
|
||||
|
||||
const trendVal = (current: number, prev: number) => ({
|
||||
pct: prev > 0 ? Math.round(((current - prev) / prev) * 100) : current > 0 ? 100 : 0,
|
||||
up: current >= prev,
|
||||
})
|
||||
|
||||
const prevFiltered = filterLeadsByPeriod(leads, period === "7days" ? "30days" : "7days")
|
||||
const prevTotal = prevFiltered.length
|
||||
const prevOpen = prevFiltered.filter((l) => l.status === "open").length
|
||||
const prevContacted = prevFiltered.filter((l) => l.status === "contacted").length
|
||||
const prevPending = prevFiltered.filter((l) => l.status === "pending").length
|
||||
const prevClosed = prevFiltered.filter((l) => l.status === "closed").length
|
||||
const prevIgnored = prevFiltered.filter((l) => l.status === "ignored").length
|
||||
const prevConversion = prevTotal > 0 ? Math.round((prevClosed / prevTotal) * 100) : 0
|
||||
|
||||
const trends = {
|
||||
totalLeads: trendVal(totalLeads, prevTotal),
|
||||
openLeads: trendVal(openLeads, prevOpen),
|
||||
contactedLeads: trendVal(contactedLeads, prevContacted),
|
||||
pendingLeads: trendVal(pendingLeads, prevPending),
|
||||
closedLeads: trendVal(closedLeads, prevClosed),
|
||||
ignoredLeads: trendVal(ignoredLeads, prevIgnored),
|
||||
conversionRate: trendVal(conversionRate, prevConversion),
|
||||
}
|
||||
|
||||
return {
|
||||
totalLeads,
|
||||
openLeads,
|
||||
@@ -46,9 +80,11 @@ export function getDashboardStats(period: string): DashboardStats {
|
||||
closedLeads,
|
||||
ignoredLeads,
|
||||
conversionRate,
|
||||
monthlyBreakdown,
|
||||
leadsPerMonth: groupLeadsByInterval(filtered, period),
|
||||
recentLeads: filtered.slice(0, 10),
|
||||
statusDistribution: getStatusDistribution(),
|
||||
periodLabel: label,
|
||||
trends,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user