X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=httemplate%2Fsearch%2Freport_tax.cgi;h=6dc9ffcfb586d318f970a7741953c5c8ad25f9e8;hb=34b6146b716903b4a4f437c95a8e403c44ba0241;hp=ac76fad6e7ad50c2add0f8cb6a34a41cda96cb97;hpb=6c2f4c44fc083bde9dd055bd4db51e65fa377379;p=freeside.git
diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi
index ac76fad6e..6dc9ffcfb 100755
--- a/httemplate/search/report_tax.cgi
+++ b/httemplate/search/report_tax.cgi
@@ -1,25 +1,788 @@
-
-<%
+<% include("/elements/header.html", "$agentname Tax Report - ".
+ ( $beginning
+ ? time2str('%h %o %Y ', $beginning )
+ : ''
+ ).
+ 'through '.
+ ( $ending == 4294967295
+ ? 'now'
+ : time2str('%h %o %Y', $ending )
+ )
+ )
+%>
+
+Download full results
+as Excel spreadsheet
+ |
+
+
+<% include('/elements/table-grid.html') %>
+
+ |
+ Sales |
+ |
+ Rate |
+ |
+ Tax owed |
+% unless ( $cgi->param('show_taxclasses') ) {
+ Tax invoiced |
+ |
+ Tax credited |
+ |
+ Tax collected |
+% }
+
+
+
+ Total |
+ |
+ Non-taxable |
+ |
+ Non-taxable |
+ |
+ Non-taxable |
+ |
+ Taxable |
+
+
+
+ (tax-exempt customer) |
+ (tax-exempt package) |
+ (monthly exemption) |
+
+
+% foreach my $class (@pkgclasses ) {
+% next if @{ $class->{regions} } == 0;
+% if ( $class->{classname} ) {
+
+ <% $class->{classname} %> |
+
+% }
+
+% my $bgcolor1 = '#eeeeee';
+% my $bgcolor2 = '#ffffff';
+% my $bgcolor;
+
+% my @regions = @{ $class->{regions} };
+% foreach my $region ( @regions ) {
+%
+% my $link = '';
+% if ( $with_pkgclass and length($class->{classnum}) ) {
+% $link = ';classnum='.$class->{classnum};
+% } # else we're not breaking down pkg class, or this is the grand total
+%
+% if ( $region->{'label'} eq $out ) {
+% $link .= ';out=1';
+% } elsif ( $region->{'taxnums'} ) {
+% # might be nicer to specify this as country:state:city
+% $link .= ';'.join(';', map { "taxnum=$_" } @{ $region->{'taxnums'} });
+% }
+%
+% if ( $bgcolor eq $bgcolor1 ) {
+% $bgcolor = $bgcolor2;
+% } else {
+% $bgcolor = $bgcolor1;
+% }
+%
+% my $hicolor = $bgcolor;
+% unless ( $cgi->param('show_taxclasses') ) {
+% my $diff = abs( sprintf( '%.2f', $region->{'owed'} )
+% - sprintf( '%.2f', $region->{'tax'} )
+% );
+% if ( $diff > 0.02 ) {
+% $hicolor = $hicolor eq '#eeeeee' ? '#eeee99' : '#ffffcc';
+% }
+% }
+%
+%
+% my $td = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
+% my $tdh = qq(TD CLASS="grid" BGCOLOR="$hicolor");
+% my $bigmath = '';
+% my $bme = '';
+
+% if ( $region->{'is_total'} ) {
+
+ Total |
+% } else {
+
+ <<%$td%>><% $region->{'label'} %>
+% }
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $region->{'sales'} ) %>
+
+% if ( $region->{'label'} eq $out ) {
+ <<%$td%> COLSPAN=12>
+% } else { #not $out
+ <<%$td%>> -
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $region->{'exempt_cust'} ) %>
+
+ <<%$td%>> -
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $region->{'exempt_pkg'} ) %>
+
+ <<%$td%>> -
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $region->{'exempt_monthly'} ) %>
+
+ <<%$td%>> =
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $region->{'taxable'} ) %>
+
+ <<%$td%>><% $region->{'label'} eq 'Total' ? '' : "$bigmath X $bme" %>
+ <<%$td%> ALIGN="right"><% $region->{'rate'} %>
+ <<%$td%>><% $region->{'label'} eq 'Total' ? '' : "$bigmath = $bme" %>
+ <<%$tdh%> ALIGN="right">
+ <% &$money_sprintf( $region->{'owed'} ) %>
+
+% } # if !$out
+% unless ( $cgi->param('show_taxclasses') ) {
+% my $invlink = $region->{'url_param_inv'}
+% ? ';'. $region->{'url_param_inv'}
+% : $link;
+
+% if ( $region->{'label'} eq $out ) {
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf_nonzero( $region->{'tax'} ) %>
+
+ <<%$td%>>
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf_nonzero( $region->{'credit'} ) %>
+
+ <<%$td%> COLSPAN=2>
+% } else { #not $out
+ <<%$tdh%> ALIGN="right">
+ <% &$money_sprintf( $region->{'tax'} ) %>
+
+ <<%$tdh%>> -
+ <<%$tdh%> ALIGN="right">
+ <% &$money_sprintf( $region->{'credit'} ) %>
+
+ <<%$tdh%>> =
+ <<%$tdh%> ALIGN="right">
+ <% &$money_sprintf( $region->{'tax'} - $region->{'credit'} ) %>
+
+% }
+% } # show_taxclasses
+
+
+% } # foreach $region
+
+%} # foreach $class
+
+
+
+% if ( $cgi->param('show_taxclasses') ) {
+
+
+ <% include('/elements/table-grid.html') %>
+
+ |
+ Tax invoiced |
+ |
+ Tax credited |
+ |
+ Tax collected |
+
+
+% #some false laziness w/above
+% foreach my $class (@pkgclasses) {
+% if ( $class->{classname} ) {
+
+ <% $class->{classname} %> |
+
+% }
+
+% my $bgcolor1 = '#eeeeee';
+% my $bgcolor2 = '#ffffff';
+% my $bgcolor;
+%
+% foreach my $region ( @{ $class->{base_regions} } ) {
+%
+% my $link = '';
+% if ( $with_pkgclass and length($class->{classnum}) ) {
+% $link = ';classnum='.$class->{classnum};
+% }
+%
+% if ( $region->{'label'} eq $out ) {
+% $link .= ';out=1';
+% } else {
+% $link .= ';'. $region->{'url_param'}
+% if $region->{'url_param'};
+% }
+%
+% if ( $bgcolor eq $bgcolor1 ) {
+% $bgcolor = $bgcolor2;
+% } else {
+% $bgcolor = $bgcolor1;
+% }
+% my $td = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
+% my $tdh = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
+%
+% #?
+% my $invlink = $region->{'url_param_inv'}
+% ? ';'. $region->{'url_param_inv'}
+% : $link;
+
+
+ <<%$td%>><% $region->{'label'} %>
+% if ( $region->{'label'} eq $out ) {
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf_nonzero( $region->{'tax'} ) %>
+
+ <<%$td%>>
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf_nonzero( $region->{'credit'} ) %>
+
+ <<%$td%> COLSPAN=2>
+% } else { #not $out
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $region->{'tax'} ) %>
+
+ <<%$td%>> -
+ <<%$tdh%> ALIGN="right">
+ <% &$money_sprintf( $region->{'credit'} ) %>
+
+ <<%$td%>> =
+ <<%$tdh%> ALIGN="right">
+ <% &$money_sprintf( $region->{'tax'} - $region->{'credit'} ) %>
+
+
+% } # if $out
+% } #foreach $region
+% } #foreach $class
+
+
+
+% } # if show_taxclasses
+
+<% include('/elements/footer.html') %>
+
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+
+my $DEBUG = $cgi->param('debug') || 0;
+
+my $conf = new FS::Conf;
+
+my $out = 'Out of taxable region(s)';
-my $user = getotaker;
+my %label_opt = ( out => 1 ); #enable 'Out of Taxable Region' label
+$label_opt{with_city} = 1 if $cgi->param('show_cities');
+$label_opt{with_district} = 1 if $cgi->param('show_districts');
-$cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/;
-my $beginning = $1;
+$label_opt{with_taxclass} = 1 if $cgi->param('show_taxclasses');
-$cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/;
-my $ending = $1;
+my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
-print header('Tax Report Results');
+my $join_cust = ' JOIN cust_bill USING ( invnum )
+ LEFT JOIN cust_main USING ( custnum ) ';
-open (REPORT, "freeside-tax-report -v -s $beginning -f $ending $user |");
+my $join_cust_pkg = $join_cust.
+ ' LEFT JOIN cust_pkg USING ( pkgnum )
+ LEFT JOIN part_pkg USING ( pkgpart ) ';
-print '';
-while() {
- print $_;
+my $from_join_cust_pkg = " FROM cust_bill_pkg $join_cust_pkg ";
+
+my $with_pkgclass = $cgi->param('show_pkgclasses');
+
+# either or both of these can be used to link cust_bill_pkg to cust_main_county
+my $pkg_tax = "SELECT SUM(amount) as tax_amount, invnum, taxnum, ".
+ "cust_bill_pkg_tax_location.pkgnum ".
+ "FROM cust_bill_pkg_tax_location JOIN cust_bill_pkg USING (billpkgnum) ".
+ "GROUP BY billpkgnum, invnum, taxnum, cust_bill_pkg_tax_location.pkgnum";
+
+my $pkg_tax_exempt = "SELECT SUM(amount) AS exempt_charged, billpkgnum, taxnum ".
+ "FROM cust_tax_exempt_pkg EXEMPT_WHERE GROUP BY billpkgnum, taxnum";
+
+my $where = "WHERE _date >= $beginning AND _date <= $ending ";
+# SELECT/GROUP clauses for first-level queries
+# classnum is a placeholder; they all go in one class in this case.
+my $select = "SELECT NULL AS classnum, cust_main_county.taxnum, ";
+my $group = "GROUP BY cust_main_county.taxnum";
+# SELECT/GROUP clauses for second-level (totals) queries
+my $select_all = "SELECT NULL AS classnum, ";
+my $group_all = "";
+
+if ( $with_pkgclass ) {
+ $select = "SELECT COALESCE(part_pkg.classnum,0), cust_main_county.taxnum, ";
+ $group = "GROUP BY part_pkg.classnum, cust_main_county.taxnum";
+ $select_all = "SELECT COALESCE(part_pkg.classnum,0), ";
+ $group_all = "GROUP BY COALESCE(part_pkg.classnum,0)";
}
-print '
';
-print '