summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2015-10-26 23:44:19 -0700
committerMark Wells <mark@freeside.biz>2015-10-26 23:44:45 -0700
commit83a9d7e9afedfa270dcdf942df04fb50989afc4f (patch)
treed388b2821a38b858128e3132421c8e01bb30b320 /httemplate
parent27f72f8225edc0d903ce534613ad037b7baf3bcf (diff)
show "out of taxable region" credits on tax report, #37088
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/search/cust_credit_bill_pkg.html53
-rwxr-xr-xhttemplate/search/report_tax-xls.cgi13
-rw-r--r--httemplate/search/report_tax.cgi27
3 files changed, 60 insertions, 33 deletions
diff --git a/httemplate/search/cust_credit_bill_pkg.html b/httemplate/search/cust_credit_bill_pkg.html
index 5facd4ab3..b9bbc4dbb 100644
--- a/httemplate/search/cust_credit_bill_pkg.html
+++ b/httemplate/search/cust_credit_bill_pkg.html
@@ -210,37 +210,34 @@ 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
- $loc_sql =~ s/\?/'cust_main_county.'.shift(@param)/e;
+ my $has_taxname = '';
+ if ( $cgi->param('taxname') ) {
+ $has_taxname = " AND COALESCE(cust_main_county.taxname, 'Tax') = "
+ . dbh->quote( $cgi->param('taxname') );
}
- $loc_sql =~ s/cust_pkg\.locationnum/cust_bill_pkg_tax_location.locationnum/g
- if $cgi->param('istax');
-
- push @where, "
- 0 = (
- SELECT COUNT(*) FROM cust_main_county
- WHERE cust_main_county.tax > 0
- AND $loc_sql
- )
- ";
-
- #not linked to by anything, but useful for debugging "out of taxable region"
- if ( grep $cgi->param($_), @loc_param ) {
-
- 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;
-
- }
+ # use the exact criteria from the tax report
+ push @where,
+ "NOT EXISTS(
+ SELECT 1 FROM cust_tax_exempt_pkg
+ JOIN cust_main_county USING (taxnum)
+ WHERE cust_tax_exempt_pkg.billpkgnum = cust_bill_pkg.billpkgnum
+ AND cust_tax_exempt_pkg.creditbillpkgnum IS NULL
+ $has_taxname
+ )
+ AND NOT EXISTS(
+ SELECT 1 FROM cust_bill_pkg_tax_location
+ JOIN cust_main_county USING (taxnum)
+ WHERE cust_bill_pkg_tax_location.taxable_billpkgnum = cust_bill_pkg.billpkgnum
+ $has_taxname
+ )
+ AND NOT EXISTS(
+ SELECT 1 FROM cust_bill_pkg_tax_location
+ JOIN cust_main_county USING (taxnum)
+ WHERE cust_bill_pkg_tax_location.billpkgnum = cust_bill_pkg.billpkgnum
+ $has_taxname
+ )";
} elsif ( $cgi->param('country') ) {
diff --git a/httemplate/search/report_tax-xls.cgi b/httemplate/search/report_tax-xls.cgi
index 773b403f1..9b02457b0 100755
--- a/httemplate/search/report_tax-xls.cgi
+++ b/httemplate/search/report_tax-xls.cgi
@@ -221,11 +221,11 @@ foreach my $row (@rows) {
}
# at the end of everything
-if ( $report->{outside} > 0 ) {
+if ( $report->{out_sales} > 0 ) {
my $f = $format[0];
$ws->set_row($y, 30); # height
$ws->write($y, 0, mt('Out of taxable region'), $f->{rowhead_outside});
- $ws->write($y, 1, $report->{outside}, $f->{currency_outside});
+ $ws->write($y, 1, $report->{out_sales}, $f->{currency_outside});
$y++;
}
@@ -292,6 +292,15 @@ foreach my $row (@rows) {
$prev_row = $row;
}
+if ( $report->{out_credit} > 0 ) {
+ my $f = $format[0];
+ $ws->set_row($y, 30); # height
+ $ws->write($y, 0, mt('Out of taxable region'), $f->{rowhead_outside});
+ $ws->write($y, 1, $report->{out_credit}, $f->{currency_outside});
+ $y++;
+}
+
+
for my $x (0..4) {
$ws->set_column($x, $x, $widths[$x]);
}
diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi
index 9e625c80f..bbb3bc199 100644
--- a/httemplate/search/report_tax.cgi
+++ b/httemplate/search/report_tax.cgi
@@ -167,7 +167,7 @@ TD.rowhead { font-weight: bold; text-align: left; padding: 0px 3px }
% } # foreach my $row
% # at the end of everything
</TBODY>
-% if ( $report->{outside} > 0 ) {
+% if ( $report->{out_sales} > 0 ) {
<TBODY CLASS="total" STYLE="background-color: #cccccc; line-height: 3">
<TR>
<TD CLASS="rowhead">
@@ -175,7 +175,7 @@ TD.rowhead { font-weight: bold; text-align: left; padding: 0px 3px }
</TD>
<TD STYLE="text-align: right">
<A HREF="<% $saleslink %>;out=1;taxname=<% encode_entities($params{'taxname'}) %>">
- <% $money_sprintf->( $report->{outside } ) %>
+ <% $money_sprintf->( $report->{out_sales } ) %>
</A>
</TD>
<TD COLSPAN=0></TD>
@@ -253,7 +253,28 @@ TD.rowhead { font-weight: bold; text-align: left; padding: 0px 3px }
% $rownum++;
% $prev_row = $row;
% } # foreach my $row
-% # no "out of taxable region" for credits (yet)
+% # "out of taxable region" for credits (there is a need for it)
+% if ( $report->{out_credit} > 0 ) {
+% my $creditlink = "cust_credit_bill_pkg.html?out=1;$dateagentlink";
+% if ( $params{'credit_date'} eq 'cust_credit_bill' ) {
+% $creditlink =~ s/begin/credit_begin/;
+% $creditlink =~ s/end/credit_end/;
+% }
+% $creditlink .= ";taxname=" . encode_entities($params{'taxname'});
+ <TBODY CLASS="total" STYLE="background-color: #cccccc; line-height: 3">
+ <TR>
+ <TD CLASS="rowhead">
+ <% emt('Out of taxable region') %>
+ </TD>
+ <TD STYLE="text-align: right">
+ <A HREF="<% $creditlink %>">
+ <% $money_sprintf->( $report->{out_credit } ) %>
+ </A>
+ </TD>
+ <TD COLSPAN=0></TD>
+ </TR>
+ </TBODY>
+% }
</TBODY>
</TABLE>