} elsif ( scalar( grep( /locationtaxid/, $cgi->param ) ) ) {
- # this should really be shoved out to FS::cust_pkg->location_sql or something
- # along with the code in report_newtax.cgi
-
- my %pn = (
- 'county' => 'tax_rate_location.county',
- 'state' => 'tax_rate_location.state',
- 'city' => 'tax_rate_location.city',
- 'locationtaxid' => 'cust_bill_pkg_tax_rate_location.locationtaxid',
- );
-
- my %ph = map { ( $pn{$_} => dbh->quote( $cgi->param($_) || '' ) ) }
- qw( city county state locationtaxid );
-
- push @where,
- join( ' AND ', map { "( $_ = $ph{$_} OR $ph{$_} = '' AND $_ IS NULL)" }
- keys %ph
- );
+ push @where, FS::tax_rate_location->location_sql(
+ map { $_ => (scalar($cgi->param($_)) || '') }
+ qw( city county state locationtaxid )
+ );
} elsif ( $cgi->param('unearned_now') =~ /^(\d+)$/ ) {
$count_query .= "SUM(usage)";
} elsif ( $unearned ) {
$count_query .= "SUM(cust_bill_pkg.recur)";
+ } elsif ( scalar( grep( /locationtaxid/, $cgi->param ) ) ) {
+ $count_query .= "SUM( COALESCE(cust_bill_pkg_tax_rate_location.amount, cust_bill_pkg.setup + cust_bill_pkg.recur))";
+ } elsif ( $cgi->param('iscredit') eq 'rate') {
+ $count_query .= "SUM( cust_credit_bill_pkg.amount )";
} else {
- if ( scalar( grep( /locationtaxid/, $cgi->param ) ) ||
- $cgi->param('iscredit') eq 'rate') {
- $count_query .= "SUM( COALESCE(amount, cust_bill_pkg.setup + cust_bill_pkg.recur))";
- } else {
- $count_query .= "SUM(cust_bill_pkg.setup + cust_bill_pkg.recur)";
- }
+ $count_query .= "SUM(cust_bill_pkg.setup + cust_bill_pkg.recur)";
}
if ( $unearned ) {