+ # taxname
+ if ( $cgi->param('taxnameNULL') ) {
+ push @tax_where, 'cust_main_county.taxname IS NULL OR '.
+ 'cust_main_county.taxname = \'Tax\'';
+ } elsif ( $cgi->param('taxname') ) {
+ push @tax_where, 'cust_main_county.taxname = '.
+ dbh->quote($cgi->param('taxname'));
+ }
+
+ # itemdesc, for breakdown from the vendor tax report
+ # (is this even used? vendor tax report shouldn't use cust_bill_pkg.cgi)
+ 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'));
+ }
+ }
+
+ # specific taxnums (the usual way)
+ if ( $cgi->param('taxnum') =~ /^([\d,]+)$/) {
+ push @tax_where, "cust_main_county.taxnum IN ($1)";
+ }
+
+ $tax_subquery = "$tax_select $tax_from";
+
+ } # end of internal-tax case
+
+ if (@tax_where) {
+ $tax_subquery .= '
+ WHERE ' . join(' AND ', map "($_)", @tax_where);
+ }
+ $tax_subquery .= ' GROUP BY tax.billpkgnum ';
+
+ # now join THAT into the main report
+ # (inner join, so that tax line items that don't match the tax_where
+ # conditions don't appear in the output.)
+
+ $join_pkg .= " JOIN ($tax_subquery) AS _istax USING (billpkgnum) ";
+
+ push @select, 'tax_total';
+
+ @peritem = ( 'setup' ); # total tax on the invoice, not just the filtered tax
+ @peritem_desc = ( 'Tax charge' );
+
+ @total = ( 'COUNT(cust_bill_pkg.billpkgnum)',
+ 'SUM(cust_bill_pkg.setup)' );
+ @total_desc = ( "$money_char%.2f total tax" );
+
+ if ( @tax_where ) {
+ # then also show the filtered tax
+ push @peritem, 'tax_total';
+ push @peritem_desc, 'Tax in category';
+ push @total, 'SUM(tax_total)';
+ push @total_desc, "$money_char%.2f tax in this category";
+ # would also be nice to include a line explaining what the category is