Fixed invoice inconsistencies with various conf flags RT#78190
authorMitch Jackson <mitch@freeside.biz>
Wed, 15 Nov 2017 07:51:40 +0000 (07:51 +0000)
committerMitch Jackson <mitch@freeside.biz>
Thu, 16 Nov 2017 05:30:09 +0000 (05:30 +0000)
commit22dd0016d0938f6acb2127d8168a4a1c5e296d3f
tree361e4a80f7f8812a1d6506d303c97430ad277c30
parentf228534e7bc57e615657d6a8b9c09069f34f914e
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