(and REALLY fix the line-item links too, whew) fix overreporting of tax invoiced...
[freeside.git] / httemplate / search / cust_bill_pkg.cgi
index d9f2548..1a95d01 100644 (file)
@@ -119,11 +119,39 @@ if ( $cgi->param('out') ) {
     " ( state   = $state  OR $state  = '' ) ",
     "   country = $country "
   ;
+  if ( $cgi->param('taxname') ) {
+    push @where, 'itemdesc = '. dbh->quote( $cgi->param('taxname') );
+  #} elsif ( $cgi->param('taxnameNULL') {
+  } else {
+    push @where, "( itemdesc IS NULL OR itemdesc = '' OR itemdesc = 'Tax' )";
+  }
+
   push @where, ' taxclass = '. dbh->quote( $cgi->param('taxclass') )
     if $cgi->param('taxclass');
 
+  if ( $cgi->param('taxclassNULL') ) {
+
+    my %hash = ( 'country' => scalar($cgi->param('country')) );
+    foreach (qw( state county )) {
+      $hash{$_} = scalar($cgi->param($_)) if $cgi->param($_);
+    }
+    my $cust_main_county = qsearchs('cust_main_county', \%hash);
+    die "unknown base region for empty taxclass" unless $cust_main_county;
+
+    my $same_sql = $cust_main_county->sql_taxclass_sameregion;
+    push @where, $same_sql if $same_sql;
+
+  }
+
 }
 
+if ($cgi->param('itemdesc')) {
+  if ($cgi->param('itemdesc') eq 'Tax') {
+    push @where, "(itemdesc='Tax' OR itemdesc is null)";
+  }else{
+    push @where, 'itemdesc='. dbh->quote($cgi->param('itemdesc'));
+  }
+}
 push @where, 'pkgnum != 0' if $cgi->param('nottax');
 push @where, 'pkgnum  = 0' if $cgi->param('istax');
 
@@ -185,7 +213,7 @@ my $query = {
                    FS::UI::Web::cust_sql_fields(),
                  ),
   'extra_sql' => $where,
-  'order_by'  => 'ORDER BY _date',
+  'order_by'  => 'ORDER BY _date, billpkgnum',
 };
 
 my $ilink = [ "${p}view/cust_bill.cgi?", 'invnum' ];