+ if ( !$unearned_mode or $unearned_mode eq 'billed' ) {
+ $unearned_base = 'cust_bill_pkg.recur';
+ }
+ elsif ( $unearned_mode eq 'paid' ) {
+ $join_pkg .= "JOIN (
+ SELECT billpkgnum, SUM(cust_bill_pay_pkg.amount) AS total_paid
+ FROM cust_bill_pay_pkg
+ JOIN cust_bill_pay USING (billpaynum)
+ JOIN cust_pay USING (paynum)
+ WHERE cust_bill_pay_pkg.setuprecur = 'recur'
+ AND cust_pay._date <= $unearned
+ GROUP BY billpkgnum
+ ) AS cust_bill_pkg_paid USING (billpkgnum)";
+ $unearned_base = 'total_paid';
+ push @select, 'total_paid';
+ }
+ else {
+ die "invalid mode '$unearned_mode'";
+ }