mirror of
https://github.com/Sea-Haven-Industries/payments-dashboard.git
synced 2026-09-30 06:33:11 +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();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
|
||||
// Categorize payments by status
|
||||
const scheduled = [];
|
||||
const outstanding = [];
|
||||
const cleared = [];
|
||||
// Categorize payments
|
||||
const scheduledChecks = [];
|
||||
const scheduledACH = [];
|
||||
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) {
|
||||
if (p.method !== "ACH" && p.method !== "Check") continue;
|
||||
|
|
@ -117,20 +119,17 @@ function buildHomeView(payments, metadata) {
|
|||
if (!dt) continue;
|
||||
|
||||
const status = (p.status || "").toLowerCase();
|
||||
|
||||
// Skip voided/cancelled payments entirely
|
||||
if (skipStatuses.includes(status)) continue;
|
||||
|
||||
if (status === "cleared") {
|
||||
cleared.push(p);
|
||||
} else if (status === "outstanding") {
|
||||
outstanding.push(p);
|
||||
} else if (dt < today) {
|
||||
// Past due date but not yet confirmed cleared — outstanding
|
||||
outstanding.push(p);
|
||||
} else {
|
||||
scheduled.push(p);
|
||||
if (dt >= today) {
|
||||
// Future — scheduled
|
||||
if (p.method === "Check") scheduledChecks.push(p);
|
||||
else scheduledACH.push(p);
|
||||
} else if (p.method === "Check") {
|
||||
// Past-due check not cleared — outstanding
|
||||
outstandingChecks.push(p);
|
||||
}
|
||||
// Past-due ACH not cleared is ignored (should have been auto-cleared)
|
||||
}
|
||||
|
||||
// Sort by date
|
||||
|
|
@ -139,11 +138,14 @@ function buildHomeView(payments, metadata) {
|
|||
const db = parseMDYLocal(b.send_payment_on);
|
||||
return (da || 0) - (db || 0);
|
||||
};
|
||||
scheduled.sort(byDate);
|
||||
outstanding.sort(byDate);
|
||||
cleared.sort(byDate);
|
||||
scheduledChecks.sort(byDate);
|
||||
scheduledACH.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 blocks = [
|
||||
|
|
@ -196,6 +198,52 @@ function buildHomeView(payments, metadata) {
|
|||
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 {
|
||||
type: "home",
|
||||
blocks: [
|
||||
|
|
@ -211,9 +259,9 @@ function buildHomeView(payments, metadata) {
|
|||
],
|
||||
},
|
||||
{ type: "divider" },
|
||||
...buildSectionBlocks("Scheduled", ":calendar:", scheduled),
|
||||
...buildSectionBlocks("Outstanding", ":warning:", outstanding),
|
||||
...buildSectionBlocks("Cleared", ":white_check_mark:", cleared),
|
||||
...buildScheduledBlocks("Scheduled Checks", ":calendar:", scheduledChecks),
|
||||
...buildScheduledBlocks("Scheduled ACH", ":calendar:", scheduledACH),
|
||||
...buildOutstandingBlocks(),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue