-my $pay_sub = "SELECT SUM(cust_bill_pay_pkg.amount) AS pay_amount,
- billpkgnum
- FROM cust_bill_pay_pkg
- GROUP BY billpkgnum";
-$join_pkg .= " LEFT JOIN ($pay_sub) AS item_pay USING (billpkgnum)";
-push @select, 'item_pay.pay_amount';
-
-
-# credit
-if ( $cgi->param('credit') ) {
-
- my $credit_sub;
-
- if ( $cgi->param('istax') ) {
- # then we need to group/join by billpkgtaxlocationnum, to get only the
- # relevant part of partial taxes
- my $credit_sub = "SELECT SUM(cust_credit_bill_pkg.amount) AS credit_amount,
- reason.reason as reason_text, access_user.username AS username_text,
- billpkgtaxlocationnum, billpkgnum
- FROM cust_credit_bill_pkg
- JOIN cust_credit_bill USING (creditbillnum)
- JOIN cust_credit USING (crednum)
- LEFT JOIN reason USING (reasonnum)
- LEFT JOIN access_user USING (usernum)
- GROUP BY billpkgnum, billpkgtaxlocationnum, reason.reason,
- access_user.username";
-
- if ( $cgi->param('out') ) {
-
- # find credits that are applied to the line items, but not to
- # a cust_bill_pkg_tax_location link
- $join_pkg .= " LEFT JOIN ($credit_sub) AS item_credit
- USING (billpkgnum)";
- push @where, 'item_credit.billpkgtaxlocationnum IS NULL';
-
- } else {
-
- # find credits that are applied to the CBPTL links that are
- # considered "interesting" by the report criteria
- $join_pkg .= " LEFT JOIN ($credit_sub) AS item_credit
- USING (billpkgtaxlocationnum)";