Commit Graph

3 Commits

Author SHA1 Message Date
a08a02ad4b feat(statements): top up open late-fee invoices instead of stacking new ones
Statement generation raised a fresh LPF invoice every month, so a customer
who never paid accumulated a pile of small invoices, each carrying the flat
dunning_fee again. Interest was also recomputed from each invoice's due date
every run, re-billing periods already charged for.

Now a customer gets one fee invoice per collections episode:

- While an earlier fee invoice still carries a balance, the next run amends
  it and appends the new period's interest as a further line item, rather
  than creating a second invoice.
- Payment Entries allocated to a partly paid fee invoice are unlinked by the
  cancellation and re-applied to the amended invoice via
  reconcile_against_document (the primitive Payment Reconciliation uses), so
  the outstanding amount and Payment Ledger stay correct.
- Original posting and due dates are carried over. Re-dating to today would
  reset the invoice to Current in the statement's aging buckets and hide how
  long the balance has been owed.
- Interest accrues from the last run, tracked by a new
  custom_late_fee_billed_upto field on Sales Invoice, so no period is billed
  twice. Fee invoices predating the field fall back to their posting date,
  which is when they were billed, so no migration patch is needed.
- The flat dunning_fee is charged once, when a fee invoice is first raised,
  not again on every top-up.
- Unpaid fee invoices are in the interest base on the same terms as any
  other overdue receivable, so interest compounds onto the fee balance.

Amending means cancelling, which is only reversible for links we can
restore. If the open fee invoice has a Journal Entry or credit note applied,
a negative payment allocation, or a posting date in a frozen period, it is
left alone, the charge goes on a new invoice, and the reason is recorded on
the customer's timeline.

Verified against nsi.local with two rolled-back integration probes covering
the amend + re-link path (including two consecutive amendments) and the
blocked-amend fallback.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-13 06:15:55 -04:00
0aefdeb5ff fix(statements): set envelope geometry for #9 double-window
Reset the statement window positions to the app's proven #9 (9x4)
double-window geometry, mirroring sales_invoice_ns.html — recipient
window at top:1.5in/left:1.125in. It previously copied the dunning
format's 1.9in, which sits too low for a #9. Tighten the body
padding-top to keep clearance below the higher window, and correct the
stale #10 references in the template comment and docs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-09 07:52:07 -04:00
5181f4a177 docs: describe the customer statements feature
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 19:58:09 -04:00