Charts and metrics
Revenue, growth, ARR and pipeline numbers are worked out in the browser from the sample records. This page shows where each number comes from and how to work it out in your database instead.
Where the numbers come from
| Number | Worked out in | From |
|---|---|---|
| Collected and invoiced per month | collectedByMonth, invoicedByMonth | Successful payments; invoices by issue date |
| ARR and live customers per month | arrByMonth, liveCustomersByMonth | Contracts live at the end of each month |
| Collected by plan | collectedByPlan | Payments, by contract plan |
| A customer's revenue and growth | revenueByMonth, growthOf | That customer's payments |
| Pipeline, weighted value, win rate, funnel | pipelineStats, stageReach | Leads and their stage history |
| Outstanding, overdue, ageing | useInvoices() | Invoices and payments (see Invoices) |
The monthly functions are in src/lib/data/trends.ts and src/lib/data/growth.ts; the pipeline ones in src/lib/data/leads.ts. All months end at DEMO_TODAY, the fixed date the sample data is built around.
Revenue and growth
A customer's revenue for a month counts each payment toward the months it pays for: a yearly payment is spread over 12 months and a quarterly one over 3. So a customer billed once a year doesn't look like it grew and then shrank to nothing.
Growth compares the last 6 months with the 6 before. A customer with no revenue in the earlier 6 months shows "New". The rating follows from growth (ratingForGrowth): Excellent from +50%, Good from +10%, Normal within ±10%, Bad down to −40% and Very Bad below that, unless someone sets a rating by hand.
Work it out in your database
Working these out in the browser means loading every payment and contract. With real data, let the database do it and send the app only the totals. A view for collected per month:
And a customer's revenue, spread over the months each payment covers:
Growth is then two sums over that view. For dashboards many people open, keep the results in a table refreshed by a scheduled job, or a materialized view.
Keep the screens the same
The cards and charts only need arrays of numbers in month order, oldest first. Fetch the totals on the server and pass them where the card calls the function today, for example collectedByMonth(range) in the Collected vs invoiced card. Use the same month keys (lastMonths, monthLabel) with today's date in place of DEMO_TODAY, and fill months with no payments with 0 so the line doesn't skip.