Hub 2.0 step 4: billing per customer
- One invoice per customer per period for all its products; the schedule moves from Licence to Customer (migration copies it, so billing carries on unchanged); licences get billedFrom / billedUntil - Website (R99, 5 GB) and App (on active members) prices next to the Events tiers; founding prices per product, then bundles (15% two, 25% three); extra website storage R20 per 5 GB, never discounted - A product added to a billed customer starts after its free month; days before its first full period are prorated, never charged twice - Annual review per product (Events income, App members), one notice of licence change per product; invoices, PDFs and emails name products - Customer page: schedule, per-product billing, next-invoice preview - Invoices from before 2.0 kept as they were (still recalculable) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,16 @@ model Customer {
|
||||
founding Boolean @default(false)
|
||||
foundingSince DateTime? @db.Date
|
||||
foundingNote String?
|
||||
// Hub 2.0: one invoice per customer per period for all its products (moved from Licence).
|
||||
// none = not invoiced. Invoices are in advance: each covers the period starting on its date.
|
||||
billingCycle BillingCycle @default(none)
|
||||
// The day billing started; its day of the month is the billing day.
|
||||
billingStart DateTime? @db.Date
|
||||
// The start of the next period to invoice (the draft is made 14 days before).
|
||||
nextInvoiceDate DateTime? @db.Date
|
||||
// The next annual tier review: the first invoice for a period starting on or after it uses
|
||||
// what each product reports (Events: 12-month event income; App: active members).
|
||||
reviewDate DateTime? @db.Date
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
licences Licence[]
|
||||
@@ -85,16 +95,12 @@ model Licence {
|
||||
// Markup on the real AI cost, in %. Null = the Hub default (Settings → AI).
|
||||
aiMarkupPercent Int?
|
||||
notes String?
|
||||
// Billing (1.7.0). none = not invoiced (trial, free). Invoices are in advance: each covers
|
||||
// the period starting on its date.
|
||||
billingCycle BillingCycle @default(none)
|
||||
// The day billing started; its day of the month is the billing day.
|
||||
billingStart DateTime? @db.Date
|
||||
// The start of the next period to invoice (the draft is made 14 days before).
|
||||
nextInvoiceDate DateTime? @db.Date
|
||||
// The next annual tier review: the first invoice for a period starting on or after it
|
||||
// uses the last 12 months' event income.
|
||||
reviewDate DateTime? @db.Date
|
||||
// Billing (Hub 2.0: the schedule is the customer's). The licence is charged from billedFrom
|
||||
// (null = not charged: a trial, free, or Accounts); a product added to a customer already
|
||||
// billed starts after its free month. billedUntil is the last day an invoice has covered, so a
|
||||
// product that starts mid-period gets a prorated line on the next invoice.
|
||||
billedFrom DateTime? @db.Date
|
||||
billedUntil DateTime? @db.Date
|
||||
// A price per month instead of the tier's (e.g. the Network tier), in cents.
|
||||
customMonthlyCents Int?
|
||||
createdAt DateTime @default(now())
|
||||
@@ -318,7 +324,9 @@ model Invoice {
|
||||
incomeBand String?
|
||||
reviewed Boolean @default(false)
|
||||
founding Boolean @default(false)
|
||||
// A tier change that comes with this invoice: { from, to, fromMonthlyCents, toMonthlyCents }.
|
||||
// Tier changes that come with this invoice. Hub 2.0: a list, one per product,
|
||||
// [{ licenceId, product, from, to, fromMonthlyCents, toMonthlyCents, band }]; before 2.0 one
|
||||
// object { from, to, … } (read with compute.planChangesOf).
|
||||
planChange Json?
|
||||
// [{ description, quantity, unitCents, amountCents }]
|
||||
lines Json
|
||||
@@ -330,6 +338,9 @@ model Invoice {
|
||||
// Things Joshua should check before approving (e.g. no income band reported).
|
||||
warnings String[] @default([])
|
||||
recipientEmail String?
|
||||
// Hub 2.0: what a customer invoice was worked out from, so a draft can be recalculated:
|
||||
// { licences: [{ id, billedUntil }], planChangeDropped }.
|
||||
basis Json?
|
||||
approvedAt DateTime?
|
||||
approvedById String?
|
||||
approvalEmailedAt DateTime?
|
||||
@@ -344,7 +355,10 @@ model Invoice {
|
||||
payments Payment[]
|
||||
licenceChanges LicenceChange[]
|
||||
|
||||
@@unique([licenceId, periodStart])
|
||||
// Before Hub 2.0 an invoice was for one licence's period. From 2.0 it's for the customer's
|
||||
// period (licenceId null): one per customer per period that isn't void, enforced by the partial
|
||||
// unique index "Invoice_customerId_periodStart_open_key" (migration …_billing_per_customer).
|
||||
@@index([licenceId, periodStart])
|
||||
@@index([status, issueDate])
|
||||
@@index([customerId])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user