Progress Cards for Top Payees

This commit is contained in:
2026-04-25 12:41:05 +05:30
parent 71afc157ff
commit 89ad8e376e
8 changed files with 59 additions and 18 deletions

View File

@@ -50,6 +50,7 @@ const toPoints = (
export function mapReportToDashboard(
weekly: ReportBucket[],
monthly: ReportBucket[],
payeeBuckets: ReportBucket[],
type: "expense" | "income"
): AggregatedDashboardData {
const flow = type === "expense" ? "expenses" : "incomes";
@@ -75,7 +76,9 @@ export function mapReportToDashboard(
const payeeMap: Record<string, number> = {};
for (const b of weekly) {
const sourceForPayees = (payeeBuckets && payeeBuckets.length > 0) ? payeeBuckets : weekly;
for (const b of sourceForPayees) {
for (const g of b.groups) {
const key = g.group_key || "Unknown";
const amt = g?.[flow]?.sum || 0;
@@ -84,6 +87,7 @@ export function mapReportToDashboard(
}
const topPayees = Object.entries(payeeMap)
// .filter(([name]) => name !== "Unknown")
.map(([payeeName, amount]) => ({ payeeName, amount }))
.sort((a, b) => b.amount - a.amount)
.slice(0, 5);