Functional Weave
Code in TypeScript

education.fee-instalments@1.0.0

README.md

1,340 bytes · view raw

# education.fee-instalments

A payment schedule for a tuition fee: the total split into instalments by the
shares given (25/25/50 across three terms, equal thirds, ten monthly
payments), each with its due date, the running total paid and what is left.
The amounts always add up to the fee exactly.

## Decisions

- **Split by `money.allocate`.** Each instalment gets its share rounded down,
  and the pennies left over go to the instalments with the largest
  remainders, ties to the earlier one. So £9,535 in thirds is £3,178.34,
  £3,178.33, £3,178.33, and £1,000.01 split 25/25/50 puts the odd penny on
  the 50% instalment, where the largest fraction of a penny was, not on the
  first. Adding a remainder to the first or last instalment by habit gives a
  different schedule from this one; say so if yours must match another system.
- **Shares are relative**, so [25, 25, 50], [1, 1, 2] and [2500, 2500, 5000]
  give the same schedule. A share of 0 is allowed (an instalment that
  collects nothing, say a deposit already paid) but not all of them.
- **Due dates are the caller's**, strictly ascending: universities and
  schools set them per term or month, so there is no rule to derive them
  from. Use `dates.add-months` or `dates.recurrence` to generate monthly
  dates.
- Fees are never negative; a refund is not a schedule.