+ $join_pkg .= " LEFT JOIN ($exempt_sub) AS item_exempt
+ ON (cust_bill_pkg.billpkgnum = item_exempt.billpkgnum)";
+
+ my $credit_sub = 'SELECT SUM(amount) AS credit_amount, billpkgnum
+ FROM cust_credit_bill_pkg GROUP BY billpkgnum';
+
+ $join_pkg .= " LEFT JOIN ($credit_sub) AS item_credit
+ ON (cust_bill_pkg.billpkgnum = item_credit.billpkgnum)";