X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=httemplate%2Fsearch%2Freport_tax.cgi;h=111f22d3d6cf59d8bd5d2007d0ee82d1a82558f3;hb=ac01b85bf09d058d3cda097dffbf4e8fce5f4305;hp=3d37c47e49df9c52881e0b8f3f98fd834099032a;hpb=36f08ea69b42f3b998a98feb04a5edb1ec81b82b;p=freeside.git
diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi
index 3d37c47e4..111f22d3d 100755
--- a/httemplate/search/report_tax.cgi
+++ b/httemplate/search/report_tax.cgi
@@ -1,224 +1,270 @@
-<% include("/elements/header.html", "$agentname Sales Tax Report - ".
- ( $beginning
- ? time2str('%h %o %Y ', $beginning )
- : ''
- ).
- 'through '.
- ( $ending == 4294967295
- ? 'now'
- : time2str('%h %o %Y', $ending )
- )
- )
-%>
-
-<% include('/elements/table-grid.html') %>
-
+<& /elements/header.html, "$agentname Tax Report: ".
+ ( $beginning
+ ? time2str('%h %o %Y ', $beginning )
+ : ''
+ ).
+ 'through '.
+ ( $ending == 4294967295
+ ? 'now'
+ : time2str('%h %o %Y', $ending )
+ ). ' - ' . $taxname
+&>
+
+Download full results
+as Excel spreadsheet
+ |
+
+
+<& /elements/table-grid.html &>
- |
- Sales |
- |
- Rate |
- |
- Tax owed |
-% unless ( $cgi->param('show_taxclasses') ) {
-
- Tax invoiced |
-% }
-
+ |
+ Sales |
+ |
+ Rate |
+ |
+ Estimated tax |
+ Tax invoiced |
+ |
+ Tax credited |
+ |
+ Net tax due |
+
- Total |
- |
- Non-taxable (tax-exempt customer) |
- |
- Non-taxable (tax-exempt package) |
- |
- Non-taxable (monthly exemption) |
- |
- Taxable |
+ Total |
+ Non-taxable |
+ Non-taxable |
+ Non-taxable |
+ Taxable |
-% my $bgcolor1 = '#eeeeee';
-% my $bgcolor2 = '#ffffff';
-% my $bgcolor;
-%
-% foreach my $region ( @regions ) {
-%
-% if ( $bgcolor eq $bgcolor1 ) {
-% $bgcolor = $bgcolor2;
-% } else {
-% $bgcolor = $bgcolor1;
-% }
-%
-% my $link = '';
-% if ( $region->{'label'} ne 'Total' ) {
-% if ( $region->{'label'} eq $out ) {
-% $link = ';out=1';
-% } else {
-% $link = ';'. $region->{'url_param'};
-% }
-% }
-%
-%
-%
-%
-%
-
-
-
- <% $region->{'label'} %> |
-
- <% $money_char %><% sprintf('%.2f', $region->{'total'} ) %>
- |
- - |
-
- <% $money_char %><% sprintf('%.2f', $region->{'exempt_cust'} ) %>
- |
- - |
-
- <% $money_char %><% sprintf('%.2f', $region->{'exempt_pkg'} ) %>
- |
- - |
-
- <% $money_char %><% sprintf('%.2f', $region->{'exempt_monthly'} ) %>
- |
- = |
-
- <% $money_char %><% sprintf('%.2f', $region->{'taxable'} ) %>
- |
- <% $region->{'label'} eq 'Total' ? '' : ' X ' %> |
- <% $region->{'rate'} %> |
- <% $region->{'label'} eq 'Total' ? '' : ' = ' %> |
-
- <% $money_char %><% sprintf('%.2f', $region->{'owed'} ) %>
- |
-% unless ( $cgi->param('show_taxclasses') ) {
-
-
- <% $money_char %><% sprintf('%.2f', $region->{'tax'} ) %>
- |
-% }
-
-
-% }
-
-
-
-% if ( $cgi->param('show_taxclasses') ) {
-
-
- <% include('/elements/table-grid.html') %>
-
- |
- Tax invoiced |
+
+ (tax-exempt customer) |
+ (tax-exempt package) |
+ (monthly exemption) |
-% #some false laziness w/above
-% $bgcolor1 = '#eeeeee';
-% $bgcolor2 = '#ffffff';
-% foreach my $region ( @base_regions ) {
-%
-% if ( $bgcolor eq $bgcolor1 ) {
-% $bgcolor = $bgcolor2;
-% } else {
-% $bgcolor = $bgcolor1;
+
+% my $row = 0;
+% my $classlink = '';
+% my $descend;
+% $descend = sub {
+% my ($data, $label) = @_;
+% if ( ref $data eq 'ARRAY' ) {
+% # then we've reached the bottom
+% my (%taxnums, %values);
+% foreach (@$data) {
+% $taxnums{ $_->[0] } = $_->[1];
+% $values{ $_->[0] } = $_->[2];
+% }
+% # finally, output
+
+% # Row label
+ <% $label |h %> |
+% # Total Sales
+% my $sales = $money_sprintf->(
+% $values{taxable} +
+% $values{exempt_cust} +
+% $values{exempt_pkg} +
+% $values{exempt_monthly}
+% );
+% my %sales_taxnums;
+% foreach my $x (qw(taxable exempt_cust exempt_pkg exempt_monthly)) {
+% foreach (split(',', $taxnums{$x})) {
+% $sales_taxnums{$_} = 1;
% }
-%
-% my $link = '';
-% #if ( $region->{'label'} ne 'Total' ) {
-% if ( $region->{'label'} eq $out ) {
-% $link = ';out=1';
-% } else {
-% $link = ';'. $region->{'url_param'};
-% }
-% #}
-%
-
-
-
- <% $region->{'label'} %> |
-
- <% $money_char %><% sprintf('%.2f', $region->{'tax'} ) %>
- |
-
-% }
-%
-% if ( $bgcolor eq $bgcolor1 ) {
-% $bgcolor = $bgcolor2;
-% } else {
-% $bgcolor = $bgcolor1;
% }
-%
-
-
-
- Total |
-
- <% $money_char %><% sprintf('%.2f', $tax ) %>
+% my $sales_taxnums = join(',', keys %sales_taxnums);
+ |
+ ">
+ <% $sales %>
+
+ |
+% # exemptions
+% foreach(qw(cust pkg)) {
+
+ ">
+ <% $money_sprintf->($values{"exempt_$_"}) %>
+
+ |
+% }
+
+ ">
+ <% $money_sprintf->($values{"exempt_monthly"}) %>
+
+ |
+% # taxable
+
+ ">
+ <% $money_sprintf->($values{taxable}) %>
+
|
+% # tax rate
+% my $rate;
+% foreach(split(',', $taxnums{tax})) {
+% $rate ||= $taxrates{$_};
+% if ($rate != $taxrates{$_}) {
+% $rate = 'variable';
+% last;
+% }
+% }
+% $rate = sprintf('%.2f', $rate) . '%' if ($rate and $rate ne 'variable');
+ × |
+ <% $rate %> |
+% # estimated tax
+ = |
+ <% $rate eq 'variable'
+ ? ''
+ : $money_sprintf->( $values{taxable} * $rate / 100 ) %>
+ |
+% # invoiced tax
+
+ ">
+ <% $money_sprintf->( $values{tax} ) %>
+
+ |
+% # credited tax
+ − |
+
+ ">
+ <% $money_sprintf->( $values{credited} ) %>
+
+ |
+% # net tax due
+ = |
+ <% $money_sprintf->( $values{tax} - $values{credited} ) %> |
-
-% }
-
+% $row = $row ? 0 : 1;
+%
+% } else { # we're not at the lowest classification
+% my @keys = sort { $a <=> $b or $a cmp $b } keys(%$data);
+% foreach my $key (@keys) {
+% my $sublabel = join(', ', grep $_, $label, $key);
+% &{ $descend }($data->{$key}, $sublabel);
+% }
+% }
+% };
+
+% my @pkgclasses = sort { $a <=> $b } keys %data;
+% foreach my $pkgclass (@pkgclasses) {
+% my $class = FS::pkg_class->by_key($pkgclass) ||
+% FS::pkg_class->new({ classname => 'Unclassified' });
+
+% if ( $breakdown{pkgclass} ) {
+
+ <% $class->classname %> |
+
+% }
+% $row = 0;
+% $classlink = "classnum=".($pkgclass || 0) if $breakdown{pkgclass};
+% &{ $descend }( $data{$pkgclass}, '' );
+% # and now totals
+
+
+% &{ $descend }( $total{$pkgclass}, 'Total' );
+
+% } # foreach $pkgclass
+
-