Functional Weave
Code in Python

finance.early-payment-discount@1.0.0

README.md

1,388 bytes · view raw

# finance.early-payment-discount

Under "2/10 net 30" a customer may take 2% off if they pay within 10 days of
the invoice date; otherwise the full amount is due in 30. This says, for a
given payment date, whether the discount is still open, how much it is, and
what to pay.

The window is inclusive: with 10 days from 1 March, a payment on 11 March still
earns the discount and one on 12 March does not. It counts calendar days from
the invoice date, the same way net 30 does in finance.payment-terms-due-date,
which also validates the terms (a discount window longer than the credit period
is refused). A payment made before the invoice date is early and earns the
discount.

The discount is the rate applied to the total with money.apply-rate, rounded
half-up to the minor unit once. `amountToPay` is the total less that discount,
so the two always add back to the total.

What the discount is taken from is the caller's choice: pass the gross invoice
total for a plain settlement discount. UK VAT on prompt payment discounts has
been due on the amount actually paid since 1 April 2015 (HMRC Revenue and
Customs Brief 49/14), which means a supplier issuing a credit note or invoicing
both options; that VAT arithmetic is finance.credit-note.calculate's and
finance.invoice.calculate's, not this function's.

A negative total is refused: credit notes do not carry settlement discounts.