Fixed invoice inconsistencies with various conf flags RT#78190
authorMitch Jackson <mitch@freeside.biz>
Tue, 8 May 2018 03:03:08 +0000 (03:03 +0000)
committerMitch Jackson <mitch@freeside.biz>
Sat, 19 May 2018 21:34:24 +0000 (21:34 +0000)
commitc059d891317e7bc09d5384e9c39bf43e01e346f0
tree9ae72ea5902f061f7b8d13721b8977ad3b13a067
parent9baab880cb616a2b9bd7812306563e2f13a4880d
Fixed invoice inconsistencies with various conf flags RT#78190

Applying different invoicing conf flags manifested different
variations of the same problem.  Addressed by this fix:

 - Incorrect items listed for Previous Balance
 - Incorrect Items listed for applied payments and credits
 - Incorrect subtotals for various sections
 - Invoice amounts, subtotals, balances displayed did not reconcile.
   Because of which data was selected for display, columns could appear
   to have bad math.  No account balances were factually incorrect.
 - Items disappearing from invoices used a payment receipts or
   "statements" giving a false impression of overpayment or credits
 - Applied payments or credits appearing on the wrong statements
 - A single applied credit appearing on up to 3 invoices
 - When viewing older invoices, future payments for future bills
   shown on, and appearing to apply to, the older invoice
 - Inconsistencies of line items and numbers between website, email,
   pdf and txt version invoices.
 - Invoice summary page numbers not matching the invoice
 - Incorrect balances shown on on aging line
 - Update item order on invoice_htmlsummary mason template

Conf flags involved in these issues:

 - disable_previous_balance
 - previous_balance-payments_since
 - previous_balance-summary_only
 - previous_balance-show_on_statements
 - previous_balance-section
 - previous_balance-exclude_from_total
 - invoice_include_aging
 - invoice_show_prior_due_date
 - invoice_usesummary

New invoice template stash variables made available:

 - aged_balance_current
 - aged_balance_30d
 - aged_balance_60d
 - aged_balance_90d

Solved by updating, or creating, FS::cust_bill helper methods that
generate data to be displayed on invoices.  These helper methods
are responsive to various conf flags.  Updated template pipeline to
use these helpers instead of inconsistent sql queries.

Resolves: #78190
See Also: #75709, #76161, #74426
FS/FS/Template_Mixin.pm
FS/FS/cust_bill.pm
conf/invoice_htmlsummary