<%- include('partials/header') %>

Analytics & Insights

Spending trends, per-job breakdowns, and AI-powered purchasing analysis.

Back to Admin
<% const _perJob = Array.isArray(perJob) ? perJob : []; const _perPerson = Array.isArray(perPerson) ? perPerson : []; const _monthly = Array.isArray(monthly) ? monthly : []; const _byTax = Array.isArray(byTax) ? byTax : []; const totalAll = _perPerson.reduce((a,p) => a + parseFloat(p.total||0), 0); const totalJobs = _perJob.length; const totalExp = _perPerson.reduce((a,p) => a + parseInt(p.count||0), 0); const topJob = _perJob[0]?.job_number || '—'; %>
$<%= totalAll.toFixed(2) %>
Total Spending
<%= totalExp %>
Total Expenses
<%= totalJobs %>
Active Jobs
<%= topJob %>
Top Spending Job

Spending by Job Number

<% if (perJob && perJob.length > 0) { %> <% } else { %>

No job data yet.

<% } %>

Spending by Employee

<% if (perPerson && perPerson.some(p => p.total > 0)) { %> <% } else { %>

No employee data yet.

<% } %>

Monthly Spending Trend

Last 6 months
<% if (monthly && monthly.length > 0) { %> <% } else { %>

Not enough data yet.

<% } %>

By Tax Type

<% if (byTax && byTax.length > 0) { %> <% } else { %>

No data.

<% } %>
<% if (perJob && perJob.length > 0) { %>

Job Number Breakdown

<% perJob.forEach(j => { %> <% const jTotal = parseFloat(j.total||0); const jCount = parseInt(j.count||0); const jAvg = jCount > 0 ? jTotal / jCount : 0; const jShare = totalAll > 0 ? (jTotal / totalAll * 100) : 0; %> <% }) %>
Job Number Expenses Total Spent Avg per Expense Share of Total
<%= j.job_number %> <%= jCount %> $<%= jTotal.toFixed(2) %> $<%= jAvg.toFixed(2) %>
<%= jShare.toFixed(1) %>%
<% } %>

AI Insights powered by Gemini

<% if (hasAiKey) { %> <% } %>
<% if (!hasAiKey) { %>

Gemini API Key Not Configured

Add GEMINI_API_KEY=your_key_here to your .env file to enable AI spending analysis.

<% } else { %>

Click Analyze Expenses to get AI-powered insights on purchasing patterns, trends, and anomalies.

<% } %>
<%- include('partials/footer') %>