update flat_introrate plan to better fit current codebase RT#4912
[freeside.git] / httemplate / search / cust_bill_pkg.cgi
index b150989..4a31611 100644 (file)
@@ -95,7 +95,10 @@ if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
   }
 }
 
-push @where, map ' taxclass = '.dbh->quote($_), $cgi->param('taxclass')
+push @where, ' ( '. join(' OR ',
+                      map ' taxclass = '.dbh->quote($_), $cgi->param('taxclass')
+                    ).
+             ' ) '
   if $cgi->param('taxclass')
   && ! $cgi->param('istax'); #no part_pkg.taxclass in this case
                              #(should we save a taxclass or a link to taxnum
@@ -166,7 +169,7 @@ if ( $cgi->param('out') ) {
     my $locs_sql =
       ' ( '. join(' OR ', map {
 
-          my %ph = ( 'county' => $_,
+          my %ph = ( 'county' => dbh->quote($_),
                      map { $_ => dbh->quote( $cgi->param($_) ) }
                        qw( state country )
                    );
@@ -271,7 +274,24 @@ if ( $cgi->param('report_group') =~ /^(=|!=) (.*)$/ && $cgi->param('istax') ) {
 push @where, 'cust_bill_pkg.pkgnum != 0' if $cgi->param('nottax');
 push @where, 'cust_bill_pkg.pkgnum  = 0' if $cgi->param('istax');
 
-push @where, " tax = 'Y' " if $cgi->param('cust_tax');
+if ( $cgi->param('cust_tax') ) {
+  #false laziness -ish w/report_tax.cgi
+  my $cust_exempt;
+  if ( $cgi->param('taxname') ) {
+    my $q_taxname = dbh->quote($cgi->param('taxname'));
+    $cust_exempt =
+      "( tax = 'Y'
+         OR EXISTS ( SELECT 1 FROM cust_main_exemption
+                       WHERE cust_main_exemption.custnum = cust_main.custnum
+                         AND cust_main_exemption.taxname = $q_taxname )
+       )
+      ";
+  } else {
+    $cust_exempt = " tax = 'Y' ";
+  }
+
+  push @where, $cust_exempt;
+}
 
 my $count_query;
 if ( $cgi->param('pkg_tax') ) {