Reporting & Analytics
Revenue reports, top products, customer lifetime value, inventory snapshots, and overdue invoice tracking. All reports accept date ranges and return structured data ready for dashboards.
Available Reports
// ReportingService provides these report methods:
//
// getRevenueReport(from, to) - Total revenue, order count, average order value
// getTopProducts(from, to, limit) - Best-selling products by revenue
// getCustomerLifetimeValues() - CLV for every customer
// getInventoryReport() - Current stock levels and valuation
// getOverdueInvoices() - Unpaid invoices past their due dateCode Examples
Revenue report:
import { createServices } from "commercio";
const { reportingService } = createServices();
// Get revenue for Q1 2026
const revenue = await reportingService.getRevenueReport(
new Date("2026-01-01"),
new Date("2026-03-31"),
);
console.log(revenue.totalRevenue); // Total in cents
console.log(revenue.orderCount); // Number of orders
console.log(revenue.averageOrderValue); // Average in centsTop products:
// Get top 5 products by revenue this month
const topProducts = await reportingService.getTopProducts(
new Date("2026-04-01"),
new Date("2026-04-30"),
5, // limit
);
topProducts.forEach((p, i) => {
console.log(`#${i + 1} ${p.productName}: $${p.totalRevenue / 100} (${p.unitsSold} sold)`);
});Customer lifetime value:
// Get lifetime value for all customers
const clvs = await reportingService.getCustomerLifetimeValues();
clvs.forEach(c => {
console.log(
`${c.customerName}: $${c.lifetimeValue / 100} over ${c.orderCount} orders`
);
});Inventory report:
// Snapshot of current inventory
const inventory = await reportingService.getInventoryReport();
inventory.forEach(item => {
console.log(
`${item.productName}: ${item.currentStock} units, ` +
`valued at $${item.stockValue / 100}`
);
});Overdue invoices:
// Get all invoices past their due date
const overdue = await reportingService.getOverdueInvoices();
overdue.forEach(inv => {
console.log(
`Invoice ${inv.invoiceNumber}: $${inv.amountDue / 100} ` +
`due ${inv.dueDate} (${inv.daysOverdue} days overdue)`
);
});