X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fsearch%2Freport_tax.cgi;h=aec91c415b09db92dabf36a8d018d2d810fc1116;hp=f37e1275d9a4497cd1d44b8e1b29f643bd313d48;hb=29a82b24b37fee37588efb96928574ac1a452d88;hpb=0c84048cb76f67fea02b1d6f86c850b26f70bdc2 diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi index f37e1275d..aec91c415 100755 --- a/httemplate/search/report_tax.cgi +++ b/httemplate/search/report_tax.cgi @@ -40,32 +40,31 @@ foreach my $r ( $label = $r->county." county, $label" if $r->county; } - my $fromwhere = " - FROM cust_bill_pkg - JOIN cust_bill USING ( invnum ) - JOIN cust_main USING ( custnum ) + my $join_pkg = " JOIN cust_pkg USING ( pkgnum ) JOIN part_pkg USING ( pkgpart ) + "; + + my $where = " WHERE _date >= $beginning AND _date <= $ending AND ( county = ? OR ? = '' ) AND ( state = ? OR ? = '' ) AND ( country = ? ) AND payby != 'COMP' "; - my @param = qw( county county state state country ); # taxclass); - - my $num_others = - scalar_sql( $r, [qw( country state state county county taxname taxname )], - "SELECT COUNT(*) FROM cust_main_county - WHERE country = ? - AND ( state = ? OR ( state IS NULL AND ? = '' ) ) - AND ( county = ? OR ( county IS NULL AND ? = '' ) ) - AND ( taxname = ? OR ( taxname IS NULL AND ? = '' ) ) " - ); - die "didn't even find self?" unless $num_others; + my $taxwhere = my $fromwhere = " + FROM cust_bill_pkg + JOIN cust_bill USING ( invnum ) + JOIN cust_main USING ( custnum ) + "; + + $fromwhere .= $join_pkg. $where; + $taxwhere .= $where; + + my @taxparam = my @param = qw( county county state state country ); - if ( $num_others > 1 ) { + if ( $r->taxclass ) { $fromwhere .= " AND ( taxclass = ? ) "; push @param, 'taxclass'; } @@ -111,8 +110,8 @@ foreach my $r ( #match itemdesc if necessary! my $named_tax = $r->taxname ? 'AND itemdesc = '. dbh->quote($r->taxname) : ''; - my $x = scalar_sql($r, \@param, - "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) $fromwhere ". + my $x = scalar_sql($r, \@taxparam, + "SELECT SUM(cust_bill_pkg.setup+cust_bill_pkg.recur) $taxwhere ". "AND pkgnum = 0 $named_tax", ); $tax += $x;