Functional Weave
Code in TypeScript

finance.accruals-prepayments@1.0.0

README.md

1,535 bytes · view raw

# finance.accruals-prepayments

The matching principle, as arithmetic: an invoice for a service that runs over
several accounting periods belongs to those periods in proportion to the days
of service in each. A year's insurance paid in January is mostly a prepayment
at the end of March; a quarter's rent billed in arrears is an accrual until the
invoice arrives. This works out each period's share; which of those shares is
the prepayment, accrual or deferred income at a balance-sheet date depends on
when the invoice was booked, and is the caller's to read off.

Days are calendar days, both ends inclusive, and the split is by
money.allocate with each period's days as its weight, so the shares always add
back to the invoice to the minor unit. The odd units go to the largest
remainders, ties to the earlier period. A year's 1,200.00 over four quarters of
90, 91, 92 and 92 days is 295.89, 299.18, 302.47 and 302.46, not four lots of
300.00 (which is what splitting by months would give).

A credit note (a negative amount) is split exactly as the invoice it reverses
and negated, so the two cancel period by period.

The periods are given, not assumed to be calendar months, because financial
years and 4-4-5 calendars do not follow the calendar. They must be in date order,
must not overlap, and together must cover every day of service; periods outside
the service are allowed and get zero days and a zero amount, so a whole year of
periods can be passed for any invoice. Each period appears in the result, in
the order given.