Hub 2.0 step 7: dashboard per product, revenue, linked products

Dashboard: monthly recurring revenue after discounts, overdue invoices,
per-product installs, latest version, behind, critical and licences.
Install page: the church's other products and whether they're listed to
this site.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 09:03:39 +02:00
co-authored by Claude Opus 5.5
parent 255ac6ae6e
commit e697564ff5
6 changed files with 125 additions and 8 deletions
+19 -1
View File
@@ -298,6 +298,24 @@ function draftCustomerInvoice({ customer, licences, settings = {} }) {
};
}
/**
* What a billed customer pays a month as things stand (Hub 2.0 dashboard): a full period of every
* product charged by now, after founding and bundle discounts, plus add-ons; a yearly invoice
* divided by 12. Days owed from before a period aren't recurring, so they're left out. Cents.
*/
function monthlyRecurringCents(customer, licences, now = new Date()) {
if (customer.billingCycle !== 'monthly' && customer.billingCycle !== 'yearly') return 0;
const start = day(customer.nextInvoiceDate || now);
const end = addDays(addMonths(start, monthsIn(customer.billingCycle), anchorDayOf({ billingStart: customer.billingStart, nextInvoiceDate: start })), -1);
const charged = licences
.filter(l => l.billedFrom && ymd(l.billedFrom) <= ymd(now))
// As if invoiced up to this period, and charged for all of it.
.map(l => ({ ...l, billedFrom: ymd(l.billedFrom) < ymd(start) ? l.billedFrom : start, billedUntil: addDays(start, -1) }));
const { lines } = customerInvoiceLines({ customer, licences: charged, period: { start, end, cycle: customer.billingCycle }, reviewed: false });
const total = lines.reduce((s, l) => s + l.amountCents, 0);
return Math.round(customer.billingCycle === 'yearly' ? total / 12 : total);
}
/** An invoice's tier changes as a list (Hub 1.7 stored one object). */
function planChangesOf(invoice) {
const pc = invoice?.planChange;
@@ -357,5 +375,5 @@ function statement({ invoices, payments, from, to }) {
module.exports = {
recipientFor, contactInstall, cleanLines, totals, planLines, productLabel, customerInvoiceLines, draftCustomerInvoice, addressMonthlyCents,
planChangesOf, invoiceState, statement, invoiceDescription, anchorDayOf, monthsIn,
planChangesOf, invoiceState, statement, invoiceDescription, anchorDayOf, monthsIn, monthlyRecurringCents,
};