diff --git a/backend/src/routes/reports.js b/backend/src/routes/reports.js index 30b9fe7..a523053 100644 --- a/backend/src/routes/reports.js +++ b/backend/src/routes/reports.js @@ -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 { diff --git a/frontend/src/pages/MultiDayReport.tsx b/frontend/src/pages/MultiDayReport.tsx index 5c50908..c24d4fe 100644 --- a/frontend/src/pages/MultiDayReport.tsx +++ b/frontend/src/pages/MultiDayReport.tsx @@ -14,6 +14,8 @@ interface DayData { daily_stats: { gross_sales: number; transaction_count: number } | null sales_breakdown: SalesCol[] daily_gross_sales?: number + audit_cash_total?: number + audit_accrual_total?: number } interface OccupancyCategoryRaw { category_id?: string | number; category_name?: string @@ -488,9 +490,13 @@ export function MultiDayReport() { {days.map((day, ri) => { const vals = BANKED_COLS.map(c => recon(day, c.key)) const reportedTotal = vals.reduce((s, v) => s + v.reported_amount, 0) - const audit = dayGrossSales(day) - const auditVar = audit - reportedTotal - const auditStyle: React.CSSProperties = Math.abs(auditVar) < 0.005 ? { background: '#d4edda', fontWeight: 700 } : auditVar < 0 ? { background: '#f8d7da', fontWeight: 700 } : { background: '#fff3cd', fontWeight: 700 } + const audit = day.audit_cash_total ?? null + const auditVar = audit != null ? audit - reportedTotal : null + const auditStyle: React.CSSProperties = audit == null + ? { background: '#f5f5f5', color: '#999', fontWeight: 700 } + : auditVar != null && Math.abs(auditVar) < 0.005 ? { background: '#d4edda', fontWeight: 700 } + : auditVar != null && auditVar < 0 ? { background: '#f8d7da', fontWeight: 700 } + : { background: '#fff3cd', fontWeight: 700 } return (