add credited sales column to tax report, #37088
[freeside.git] / httemplate / search / cust_credit_bill_pkg.html
index 63d70c2..b5a0ee9 100644 (file)
@@ -203,6 +203,7 @@ if ( $cgi->param('taxclass')
 my @loc_param = qw( district city county state country );
 
 if ( $cgi->param('out') ) {
+  # probably don't need this part
 
   my ( $loc_sql, @param ) = FS::cust_pkg->location_sql( 'ornull' => 1 );
   while ( $loc_sql =~ /\?/ ) { #easier to do our own substitution
@@ -242,6 +243,8 @@ if ( $cgi->param('out') ) {
 
     #hacky, could be more efficient.  care if it is ever used for more than the
     # tax-report_groups filtering kludge
+    # (does that even still exist? if so, correct this (or location_sql itself)
+    # to work with modern cust_location links)
 
     my $locs_sql =
       ' ( '. join(' OR ', map {
@@ -266,15 +269,24 @@ if ( $cgi->param('out') ) {
 
   } else {
 
-    my %ph = map { $_ => dbh->quote( scalar($cgi->param($_)) ) } @loc_param;
-
-    my ( $loc_sql, @param ) = FS::cust_pkg->location_sql;
-    while ( $loc_sql =~ /\?/ ) { #easier to do our own substitution
-      $loc_sql =~ s/\?/$ph{shift(@param)}/e;
+    my @loc_where;
+    foreach (@loc_param) {
+      if ( length($cgi->param($_)) ) {
+        my $quoted = dbh->quote($cgi->param($_));
+        push @loc_where, "(COALESCE(cust_location.$_, '') = $quoted)";
+      }
     }
+    my $loc_sql = join(' AND ', @loc_where);
 
-    push @where, $loc_sql;
+    #my %ph = map { $_ => dbh->quote( scalar($cgi->param($_)) ) } @loc_param;
+    #
+    #my ( $loc_sql, @param ) = FS::cust_pkg->location_sql;
+    #while ( $loc_sql =~ /\?/ ) { #easier to do our own substitution
+    #  $loc_sql =~ s/\?/$ph{shift(@param)}/e;
+    #}
 
+    push @where, $loc_sql;
+warn $loc_sql;
   }
    
   my($title, $name);