+
+
+=sub _items_credits_postbill()
+
+ Returns an array of hashrefs for credits where
+ - Credit issued after this invoice
+ - Credit applied to an invoice before this invoice
+
+ Returned hashrefs are of the format returned by _items_credits()
+
+=cut
+
+sub _items_credits_postbill {
+ my $self = shift;
+
+ my @cust_credit_bill = qsearch({
+ table => 'cust_credit_bill',
+ select => join(', ',qw(
+ cust_credit_bill.creditbillnum
+ cust_credit_bill._date
+ cust_credit_bill.invnum
+ cust_credit_bill.amount
+ )),
+ addl_from => ' LEFT JOIN cust_credit'.
+ ' ON (cust_credit_bill.crednum = cust_credit.crednum) ',
+ extra_sql => ' WHERE cust_credit.custnum = '.$self->custnum.
+ ' AND cust_credit_bill._date > '.$self->_date.
+ ' AND cust_credit_bill.invnum < '.$self->invnum.' ',
+#! did not investigate why hashref doesn't work for this join query
+# hashref => {
+# 'cust_credit.custnum' => {op => '=', value => $self->custnum},
+# 'cust_credit_bill._date' => {op => '>', value => $self->_date},
+# 'cust_credit_bill.invnum' => {op => '<', value => $self->invnum},
+# },
+ });
+
+ return map {{
+ _date => $_->_date,
+ invnum => $_->invnum,
+ amount => $_->amount,
+ creditbillnum => $_->creditbillnum,
+ }} @cust_credit_bill;
+}
+
+=sub _items_payments_postbill()
+
+ Returns an array of hashrefs for payments where
+ - Payment occured after this invoice
+ - Payment applied to an invoice before this invoice
+
+ Returned hashrefs are of the format returned by _items_payments()
+
+=cut
+
+sub _items_payments_postbill {
+ my $self = shift;
+
+ my @cust_bill_pay = qsearch({
+ table => 'cust_bill_pay',
+ select => join(', ',qw(
+ cust_bill_pay.billpaynum
+ cust_bill_pay._date
+ cust_bill_pay.invnum
+ cust_bill_pay.amount
+ )),
+ addl_from => ' LEFT JOIN cust_bill'.
+ ' ON (cust_bill_pay.invnum = cust_bill.invnum) ',
+ extra_sql => ' WHERE cust_bill.custnum = '.$self->custnum.
+ ' AND cust_bill_pay._date > '.$self->_date.
+ ' AND cust_bill_pay.invnum < '.$self->invnum.' ',
+ });
+
+ return map {{
+ _date => $_->_date,
+ invnum => $_->invnum,
+ amount => $_->amount,
+ billpaynum => $_->billpaynum,
+ }} @cust_bill_pay;
+}
+
+=sub _items_payments()
+
+ Return array of hashrefs containing payments to be shown as line-items
+ when rendering this bill.
+
+ keys for each payment item:
+ - paynum: id of payment
+ - amount: payment amount
+ - description: line item to be displayed on the bill
+
+ This method has three ways it selects which payments to display on
+ this bill:
+
+ 1) Default Case: No Conf flag for 'previous_balance-payments_since'
+
+ Returns payments that have been applied to this bill only
+
+ 2) Case:
+ Conf flag set for 'previous_balance-payments_since'
+
+ List all payments that have been recorded between the timestamps
+ of the previous invoice and this invoice
+
+ 3) Case:
+ Conf flag set for 'previous_balance-payments_since'
+ $opt{'template'} eq 'statement'
+
+ List all payments that have been recorded between the timestamps
+ of the previous invoice and the following invoice.
+
+ I am concerned with this implementation, but leaving in place as is
+ If this option is selected, while viewing an older bill, the old bill
+ will show ALL future payments for future bills, but no charges for
+ future bills. Somebody could be misled into believing they have a
+ large account credit when they don't. Also, interrupts the chain of
+ invoices as an account history... the customer could have two invoices
+ in their fileing cabinet, for two different dates, both with a line item
+ for the same duplicate payment. The accounting is technically accurate,
+ but somebody could easily become confused and think two payments were
+ made, when really those two line items on two different bills represent
+ only a single payment.
+
+=cut
+