Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Rental agreements: monthly billing from the start date
Request: a customer wants each rental agreement invoiced on the same day every month, counted from its start date (start on the 7th, invoice on the 7th), for the same amount every month. Service contracts already do this with Monthly frequency and "Align to calendar periods" unticked. Rental agreements offer only:
- Calendar Month: moves every customer onto the 1st, with a part month first.
- 28 Days: the invoice date moves every month, and a year has 13 periods at the monthly rate, so the customer pays more than they were quoted.
Spec context: the rentals spec listed this as follow-on work ("anniversary cycles
later", .ai/specs/implemented/2026-09-22-revenue-recognition-rentals-and-contracts.md
decision 10).
Sibling: contract billingAlignment = Anniversary with billingFrequency = Month
(packages/database/src/contract-schedule.ts → gridAnchor / gridPeriodStart /
periodUnits). Rentals copy its period grid and its pricing rule. Rentals do not
share its code: contracts price per contract-line unit and plan invoices, and
rentals persist rentalBillingPeriod rows per unit.
Decisions (recommended, to confirm)
- Storage: add a third value to the
rentalBillingCycleenum,'Monthly'. Do not add a separate alignment column. Alignment means nothing to28 Days, and every billing function already switches oncycle.Calendar Monthstays as it is, and so do existing agreements. - UI copies the contract Billing card: Billing Cycle cards Monthly and
28 Days, with the Align to calendar periods checkbox under them. The
checkbox is enabled only for Monthly. Ticked stores
Calendar Month, and unticked storesMonthly. An existing Calendar Month agreement shows Monthly, ticked. The Properties panel select labels the three values "Monthly", "Monthly (calendar)" and "28 Days". - The default for a new agreement stays
Calendar Month. This preserves current behavior. (Contracts default to Anniversary. We can change the default if you want.)
Behavior of Monthly
- Periods: period k is
[start + k months, start + (k+1) months − 1 day]. Each period is computed from the start date and is never chained from the previous period, so a 31 Jan start bills 31 Jan–27 Feb, then 28 Feb–30 Mar, then 31 Mar–… (the contract clamp rule). The end date and the return date still cut the last period. A holdover period that starts the day after the end date ends on the next anniversary boundary. - Price: a whole period for a Monthly unit is exactly its month rate, every month. A part period (cut by the end date, the return date or holdover) is the month rate × days used ÷ days in the whole period it belongs to. Daily and Weekly units bill the whole days or weeks the period covers, as they do on the other cycles.
- Horizon: today + 1 month. Rolling agreements still get one more period beyond the horizon.
- Due date / timing: unchanged. Advance is due on the period start, and Arrears is due on the period end.
- Sales-type lease (ASC 842): valued like Calendar Month. The payment is the month
rate, there is one period per whole month of the term (
wholeMonthsInTermalready counts anniversary months), and the rate is the annual rate. ASaleline needs a Monthly unit and a term of whole months from the start (end date = start + n months − 1 day). It does not need to start on the 1st, which removes a Calendar Month limit. - Invoice line text: the same as Calendar Month (" · Month rate").
Tasks
- 1. Migration.
pnpm db:migrate:new rental-monthly-billing-cycle→ALTER TYPE "rentalBillingCycle" ADD VALUE IF NOT EXISTS 'Monthly';. Then runpnpm db:migrateandpnpm run generate:types. - 2. Billing math (TDD). In
packages/utils/src/rental-periods.ts:RentalBillingCyclegets"Monthly". AddanniversaryPeriodEnd(startDate, from), which computes from the start date.naturalEnd,billingHorizonandperiodChargeget the new branch: a Monthly unit's charge is the rate × days ÷ days in the anniversary period. Write the tests first inrental-periods.test.ts: the 7th → 6th grid; the same amount every month; the 31 Jan clamp; return and end cuts; holdover; Arrears due dates; horizon. - 3. Lease valuation (TDD). In
packages/utils/src/lessor-lease.ts:leasePaymentTermstreats Monthly like Calendar Month, andsalesTypeRequirementErrorgets the Monthly whole-months rule. Add tests in the lessor-lease tests andpost-rental-agreement/lessor.test.ts: a mid-month 12-month term schedules 12 periods. - 4. Server functions.
create-rental-invoices/index.tsrentLineDescription: Monthly + Month gives " · Month rate". Add a test torent-line-description.test.ts.post-rental-agreementandreturn-unitalready passcyclethrough; only their types need checking. - 5. ERP. In
sales.models.ts, add"Monthly"torentalBillingCycles. Replace the literal"Calendar Month" | "28 Days"unions insales.utils.tsandRentalLeaseClassification.tsxwithRentalBillingCycle. UpdateRentalAgreementBilling.tsx(cards + checkbox, copied fromContractBillTo.tsx) and theRentalAgreementProperties.tsxselect labels. Then runlingui:extractand/translate. - 6. Docs. Update
docs/content/docs/reference/rental-agreements.mdx(cycles, example, sales-type requirements, the error text), the glossarybilling-cycleterm, and the Rentals section ofapps/erp/app/modules/sales/AGENTS.md. Then regenerate swagger (packages/database/src/swagger-docs-schema.ts, via generate:types). - 7. Verify. Run
pnpm --filter @carbon/utils test,pnpm --filter @carbon/server-functions test(rental files), the scoped typecheck for@carbon/utils,@carbon/server-functionsanderp, Biome,pnpm db:check:datasetsandpnpm db:check:backups. Then browser-test with /test: create an agreement starting on the 7th, untick the box, activate, generate invoices, and check that the periods run 7th–6th at the full month rate.
Deviations from the plan
- The helper is named
monthlyPeriodEnd, notanniversaryPeriodEnd. It reusesleaseMonthsAt/leaseMonthEndfrom@carbon/database/lease-months, which already clamp from the start date. - A Monthly term counts its months with
leaseMonthsThrough, notwholeMonthsInTerm.wholeMonthsInTermcounts 31 Jan → 27 Feb as 0 months, but billing cuts it as one whole period. - The two sales-type troubleshooting headings in the rental agreements page are
shorter. The longer headings pushed the page past the agent's read budget
(
agent.kb.test.ts).