mirror of
https://github.com/Sea-Haven-Industries/payments-dashboard.git
synced 2026-10-07 09:19:25 +00:00
Update dashboard: split scheduled by method, outstanding checks by age
- Scheduled section split into Scheduled Checks and Scheduled ACH - Remove Cleared section from dashboard - Outstanding renamed to Outstanding Checks with <=90 day and >90 day totals
This commit is contained in:
parent
c43228831d
commit
53842f0821
1 changed files with 71 additions and 23 deletions
|
|
@ -103,12 +103,14 @@ function buildHomeView(payments, metadata) {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
today.setHours(0, 0, 0, 0);
|
today.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
// Categorize payments by status
|
// Categorize payments
|
||||||
const scheduled = [];
|
const scheduledChecks = [];
|
||||||
const outstanding = [];
|
const scheduledACH = [];
|
||||||
const cleared = [];
|
const outstandingChecks = [];
|
||||||
|
|
||||||
const skipStatuses = ["voided", "cancelled", "canceled", "marked as void"];
|
const skipStatuses = ["voided", "cancelled", "canceled", "marked as void", "cleared"];
|
||||||
|
const ninetyDaysAgo = new Date(today);
|
||||||
|
ninetyDaysAgo.setDate(ninetyDaysAgo.getDate() - 90);
|
||||||
|
|
||||||
for (const p of payments) {
|
for (const p of payments) {
|
||||||
if (p.method !== "ACH" && p.method !== "Check") continue;
|
if (p.method !== "ACH" && p.method !== "Check") continue;
|
||||||
|
|
@ -117,20 +119,17 @@ function buildHomeView(payments, metadata) {
|
||||||
if (!dt) continue;
|
if (!dt) continue;
|
||||||
|
|
||||||
const status = (p.status || "").toLowerCase();
|
const status = (p.status || "").toLowerCase();
|
||||||
|
|
||||||
// Skip voided/cancelled payments entirely
|
|
||||||
if (skipStatuses.includes(status)) continue;
|
if (skipStatuses.includes(status)) continue;
|
||||||
|
|
||||||
if (status === "cleared") {
|
if (dt >= today) {
|
||||||
cleared.push(p);
|
// Future — scheduled
|
||||||
} else if (status === "outstanding") {
|
if (p.method === "Check") scheduledChecks.push(p);
|
||||||
outstanding.push(p);
|
else scheduledACH.push(p);
|
||||||
} else if (dt < today) {
|
} else if (p.method === "Check") {
|
||||||
// Past due date but not yet confirmed cleared — outstanding
|
// Past-due check not cleared — outstanding
|
||||||
outstanding.push(p);
|
outstandingChecks.push(p);
|
||||||
} else {
|
|
||||||
scheduled.push(p);
|
|
||||||
}
|
}
|
||||||
|
// Past-due ACH not cleared is ignored (should have been auto-cleared)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by date
|
// Sort by date
|
||||||
|
|
@ -139,11 +138,14 @@ function buildHomeView(payments, metadata) {
|
||||||
const db = parseMDYLocal(b.send_payment_on);
|
const db = parseMDYLocal(b.send_payment_on);
|
||||||
return (da || 0) - (db || 0);
|
return (da || 0) - (db || 0);
|
||||||
};
|
};
|
||||||
scheduled.sort(byDate);
|
scheduledChecks.sort(byDate);
|
||||||
outstanding.sort(byDate);
|
scheduledACH.sort(byDate);
|
||||||
cleared.sort(byDate);
|
|
||||||
|
|
||||||
const buildSectionBlocks = (title, emoji, items) => {
|
// Split outstanding into <=90 days and >90 days
|
||||||
|
const outstanding90 = outstandingChecks.filter((p) => parseMDYLocal(p.send_payment_on) >= ninetyDaysAgo);
|
||||||
|
const outstandingOver90 = outstandingChecks.filter((p) => parseMDYLocal(p.send_payment_on) < ninetyDaysAgo);
|
||||||
|
|
||||||
|
const buildScheduledBlocks = (title, emoji, items) => {
|
||||||
const total = items.reduce((sum, p) => sum + p.amount_usd, 0);
|
const total = items.reduce((sum, p) => sum + p.amount_usd, 0);
|
||||||
|
|
||||||
const blocks = [
|
const blocks = [
|
||||||
|
|
@ -196,6 +198,52 @@ function buildHomeView(payments, metadata) {
|
||||||
return blocks;
|
return blocks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildOutstandingBlocks = () => {
|
||||||
|
const totalAll = outstandingChecks.reduce((sum, p) => sum + p.amount_usd, 0);
|
||||||
|
|
||||||
|
const blocks = [
|
||||||
|
{
|
||||||
|
type: "section",
|
||||||
|
text: {
|
||||||
|
type: "mrkdwn",
|
||||||
|
text: `*:warning: Outstanding Checks*\n${outstandingChecks.length} checks • ${formatCurrency(totalAll)}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ type: "divider" },
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!outstandingChecks.length) {
|
||||||
|
blocks.push({
|
||||||
|
type: "section",
|
||||||
|
text: { type: "mrkdwn", text: "_None_" },
|
||||||
|
});
|
||||||
|
blocks.push({ type: "divider" });
|
||||||
|
return blocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
const total90 = outstanding90.reduce((sum, p) => sum + p.amount_usd, 0);
|
||||||
|
const totalOver90 = outstandingOver90.reduce((sum, p) => sum + p.amount_usd, 0);
|
||||||
|
|
||||||
|
blocks.push({
|
||||||
|
type: "section",
|
||||||
|
fields: [
|
||||||
|
{ type: "mrkdwn", text: `*90 days or less*` },
|
||||||
|
{ type: "mrkdwn", text: `${outstanding90.length} checks • ${formatCurrency(total90)}` },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
blocks.push({
|
||||||
|
type: "section",
|
||||||
|
fields: [
|
||||||
|
{ type: "mrkdwn", text: `*Over 90 days*` },
|
||||||
|
{ type: "mrkdwn", text: `${outstandingOver90.length} checks • ${formatCurrency(totalOver90)}` },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
blocks.push({ type: "divider" });
|
||||||
|
return blocks;
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "home",
|
type: "home",
|
||||||
blocks: [
|
blocks: [
|
||||||
|
|
@ -211,9 +259,9 @@ function buildHomeView(payments, metadata) {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ type: "divider" },
|
{ type: "divider" },
|
||||||
...buildSectionBlocks("Scheduled", ":calendar:", scheduled),
|
...buildScheduledBlocks("Scheduled Checks", ":calendar:", scheduledChecks),
|
||||||
...buildSectionBlocks("Outstanding", ":warning:", outstanding),
|
...buildScheduledBlocks("Scheduled ACH", ":calendar:", scheduledACH),
|
||||||
...buildSectionBlocks("Cleared", ":white_check_mark:", cleared),
|
...buildOutstandingBlocks(),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue