[object Object]

← back to Filemaker Mcp

auto-save: 2026-08-03T07:21:35 (2 files) — scripts/dashboard-revenue.mjs scripts/push-dashboard-revenue.sh

c991f6f4b8c8ada14d0a5bd99076de91a01a98d0 · 2026-08-03 07:21:41 -0700 · Steve Abrams

Files touched

Diff

commit c991f6f4b8c8ada14d0a5bd99076de91a01a98d0
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Mon Aug 3 07:21:41 2026 -0700

    auto-save: 2026-08-03T07:21:35 (2 files) — scripts/dashboard-revenue.mjs scripts/push-dashboard-revenue.sh
---
 scripts/dashboard-revenue.mjs     | 61 +++++++++++++++++++++++++++++++++++++++
 scripts/push-dashboard-revenue.sh | 10 +++++++
 2 files changed, 71 insertions(+)

diff --git a/scripts/dashboard-revenue.mjs b/scripts/dashboard-revenue.mjs
new file mode 100644
index 0000000..366b873
--- /dev/null
+++ b/scripts/dashboard-revenue.mjs
@@ -0,0 +1,61 @@
+// Compute the FMPro direct-invoicing revenue for the ads-dashboard (trailing 30d,
+// booked/net, matching the dashboard's Shopify window) and write an AGGREGATE-ONLY
+// JSON (no customer data). A separate push step scps it to the Kamatera box; the
+// dashboard reads it and stamps it "as of" so a stale number can't look live.
+//
+//   node scripts/dashboard-revenue.mjs           # write /tmp/fmpro-revenue.json
+//   node scripts/dashboard-revenue.mjs --print    # also print the summary
+//
+// Mirrors sales-summary.mjs semantics: booked = PAID ON ACCOUNT != 0; refunds are
+// negative booked rows that net out of dollars but don't inflate order count;
+// excludes test invoice #999999.
+
+import { writeFileSync } from 'node:fs';
+import { findRecords } from '../src/fm-client.js';
+import { loadEnv, num } from '../lib/fm-script-helpers.js';
+
+loadEnv(import.meta.url);
+
+const DB = 'invoice', LAYOUT = 'GRAND TOTAL SALES';
+const TOTAL_FIELD = 'GRAND TOTAL 2', DATE_FIELD = 'Date';
+const WINDOW_DAYS = 30, FETCH_LIMIT = 5000;
+const OUT = process.env.FMPRO_OUT || '/tmp/fmpro-revenue.json';
+const pad = (n) => String(n).padStart(2, '0');
+const fmt = (x) => `${pad(x.getMonth() + 1)}/${pad(x.getDate())}/${x.getFullYear()}`;
+
+const now = new Date(), from = new Date(Date.now() - WINDOW_DAYS * 864e5);
+const { records, dataInfo } = await findRecords(
+  DB, LAYOUT,
+  [{ [DATE_FIELD]: `${fmt(from)}...${fmt(now)}` }],
+  { limit: FETCH_LIMIT, sort: [{ fieldName: DATE_FIELD, sortOrder: 'ascend' }] },
+);
+
+// Truncation guard — same failure class as sales-summary: never report a silently
+// short fetch as a real total.
+const found = Number(dataInfo?.foundCount ?? records.length);
+const returned = Number(dataInfo?.returnedCount ?? records.length);
+const truncated = found > returned || records.length >= FETCH_LIMIT;
+
+let booked = 0, orders = 0, quotes = 0;
+for (const r of records) {
+  const f = r.fieldData || {};
+  if (String(f['Invoice'] || '').trim() === '999999') continue;
+  const paid = String(f['PAID ON ACCOUNT'] ?? '').trim();
+  const amt = num(f[TOTAL_FIELD]);
+  if (paid !== '' && num(paid) !== 0) { booked += amt; if (amt > 0) orders += 1; }
+  else quotes += 1;
+}
+
+const out = {
+  source: 'fmpro-invoicing',
+  present: !truncated,
+  truncated,
+  window: `${fmt(from)}–${fmt(now)} (last ${WINDOW_DAYS}d)`,
+  total: Math.round(booked * 100) / 100,
+  orders,
+  open_quotes: quotes,
+  generated_at: now.toISOString(),
+};
+writeFileSync(OUT, JSON.stringify(out, null, 2));
+if (process.argv.includes('--print')) console.log(out);
+console.log(`wrote ${OUT}: $${out.total.toLocaleString()} / ${out.orders} booked (${truncated ? 'TRUNCATED' : 'ok'})`);
diff --git a/scripts/push-dashboard-revenue.sh b/scripts/push-dashboard-revenue.sh
new file mode 100644
index 0000000..364f9a9
--- /dev/null
+++ b/scripts/push-dashboard-revenue.sh
@@ -0,0 +1,10 @@
+#!/bin/zsh
+# Refresh the ads-dashboard FMPro revenue number: compute on Mac2 (where FileMaker
+# is reachable) then push the aggregate-only JSON to the Kamatera box.
+# Wired to run on a schedule via launchd (see pending-approval draft) — until that's
+# approved, run manually: zsh scripts/push-dashboard-revenue.sh
+set -e
+cd "$(dirname "$0")/.."
+node scripts/dashboard-revenue.mjs
+scp -q /tmp/fmpro-revenue.json root@45.61.58.125:/root/Projects/ads-dashboard/data/fmpro.json
+echo "$(date -u +%FT%TZ) pushed fmpro.json to Kamatera"

← 92722e0 chore: v0.2.5 (session close — invoice SKU/VID audit + fix)  ·  back to Filemaker Mcp  ·  ads-dashboard revenue: FMPro 30d generator + Mac2->Kamatera e7b1887 →