Add daily audit summary cross-checks to multiday report

Fetch reports_daily_audit_summary per day. Use cash_income total as the
reconciliation audit column (independent payment cross-check vs transaction
flow). Add a second Audit (DAS) column on the sales breakdown using
accrual_income totals alongside the earned revenue Audit (ER) column —
both highlight in amber if they diverge from the configured columns gross.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-20 09:23:30 +00:00
parent fa62c7c44a
commit e9cf648f8c
2 changed files with 68 additions and 8 deletions

View file

@ -147,13 +147,24 @@ export async function reportRoutes(app) {
.filter(r => r.period === date)
.reduce((s, r) => s + (r.earned_revenue || 0), 0)
// Daily audit summary — independent cross-check from a separate Newbook endpoint
const auditRows = await fetchDailyAuditSummary(date).catch(() => [])
// cash_income amounts are negative in the API (like transaction_flow) — negate to get positive
const audit_cash_total = auditRows
.filter(r => r.report_type === 'cash_income')
.reduce((s, r) => s - parseFloat(r.amount || 0), 0)
// accrual_income amounts are positive
const audit_accrual_total = auditRows
.filter(r => r.report_type === 'accrual_income')
.reduce((s, r) => s + parseFloat(r.amount || 0), 0)
// Daily stats from payments
const grossSales = freshPayments.reduce((s, p) => s + parseFloat(p.amount), 0)
const dailyStats = grossSales > 0
? { business_date: date, gross_sales: grossSales, transaction_count: freshPayments.length }
: null
return { date, cash_up: cashUp, reconciliation, daily_stats: dailyStats, sales_breakdown: salesBreakdown, daily_gross_sales }
return { date, cash_up: cashUp, reconciliation, daily_stats: dailyStats, sales_breakdown: salesBreakdown, daily_gross_sales, audit_cash_total, audit_accrual_total }
}))
return {