X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Freport_tax.cgi;h=803b7d48f92c52ebc2f6d5f765acd83db17d56a7;hb=89da4b96c4e2fce7079be8d2729750c088f8035b;hp=bc683f8b701dc3cc632a30e350704a824b63d2c3;hpb=00f2fdb5c3c9edfe446cf453ee33b9ebc7802925;p=freeside.git
diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi
index bc683f8b7..803b7d48f 100755
--- a/httemplate/search/report_tax.cgi
+++ b/httemplate/search/report_tax.cgi
@@ -1,35 +1,786 @@
-<%
+<% include("/elements/header.html", "$agentname Tax Report - ".
+ ( $beginning
+ ? time2str('%h %o %Y ', $beginning )
+ : ''
+ ).
+ 'through '.
+ ( $ending == 4294967295
+ ? 'now'
+ : time2str('%h %o %Y', $ending )
+ )
+ )
+%>
+
+<% include('/elements/table-grid.html') %>
+
+
+ |
+ Sales |
+ |
+ Rate |
+ |
+ Tax owed |
+% unless ( $cgi->param('show_taxclasses') ) {
+ Tax invoiced |
+ |
+ Tax credited |
+ |
+ Tax collected |
+% }
+
+
+
+ Total |
+ |
+ Non-taxable (tax-exempt customer) |
+ |
+ Non-taxable (tax-exempt package) |
+ |
+ Non-taxable (monthly exemption) |
+ |
+ Taxable |
+
+
+% my $bgcolor1 = '#eeeeee';
+% my $bgcolor2 = '#ffffff';
+% my $bgcolor;
+%
+% foreach my $region ( @regions ) {
+%
+% my $link = '';
+% 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 $diff = 0;
+% 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' ? '#eeee66' : '#ffff99';
+% #} elsif ( $diff ) {
+% $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 = '';
+
+
+ <<%$td%>><% $region->{'label'} %>
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $region->{'total'} ) %>
+
+ <<%$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'} ) %>
+
+
+% unless ( $cgi->param('show_taxclasses') ) {
+% my $invlink = $region->{'url_param_inv'}
+% ? ';'. $region->{'url_param_inv'}
+% : $link;
+
+ <<%$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'} ) %>
+
+% }
+
+
+% }
+
+
+
+% if ( $cgi->param('show_taxclasses') ) {
+
+
+ <% include('/elements/table-grid.html') %>
+
+ |
+ Tax invoiced |
+ |
+ Tax credited |
+ |
+ Tax collected |
+
+
+% #some false laziness w/above
+% $bgcolor1 = '#eeeeee';
+% $bgcolor2 = '#ffffff';
+%
+% foreach my $region ( @base_regions ) {
+%
+% my $link = '';
+% 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'} %>
+ <<%$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 ( $bgcolor eq $bgcolor1 ) {
+% $bgcolor = $bgcolor2;
+% } else {
+% $bgcolor = $bgcolor1;
+% }
+% my $td = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
+
+
+ <<%$td%>>Total
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $tot_tax ) %>
+
+ <<%$td%>> -
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $tot_credit ) %>
+
+ <<%$td%>> =
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $tot_tax - $tot_credit ) %>
+
+
-use strict;
-use vars qw( $cgi $user $beginning $ending );
-use CGI;
-use CGI::Carp qw( fatalsToBrowser );
-use FS::UID qw( cgisuidsetup getotaker );
-use FS::CGI qw( header );
+
-$cgi = new CGI;
-&cgisuidsetup($cgi);
+% }
-$user = getotaker;
+<% include('/elements/footer.html') %>
-$cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/;
-$beginning = $1;
+<%init>
-$cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/;
-$ending = $1;
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
-print $cgi->header( '-expires' => '-2m' ),
- header('Tax Report Results');
+my $conf = new FS::Conf;
-open (REPORT, "freeside-tax-report -v -s $beginning -d $ending $user |");
+my $user = getotaker;
-print '';
-while() {
- print $_;
+my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
+
+my $join_cust = ' JOIN cust_bill USING ( invnum )
+ LEFT JOIN cust_main USING ( custnum ) ';
+my $join_cust_pkg = $join_cust.
+ ' LEFT JOIN cust_pkg USING ( pkgnum )
+ LEFT JOIN part_pkg USING ( pkgpart ) ';
+$join_cust_pkg .= ' LEFT JOIN cust_location USING ( locationnum )'
+ if $conf->exists('tax-pkg_address');
+
+my $from_join_cust_pkg = " FROM cust_bill_pkg $join_cust_pkg ";
+
+my $where = "WHERE _date >= $beginning AND _date <= $ending ";
+
+my( $location_sql, @base_param ) = FS::cust_pkg->location_sql;
+$where .= " AND $location_sql ";
+
+my $agentname = '';
+if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
+ my $agent = qsearchs('agent', { 'agentnum' => $1 } );
+ die "agent not found" unless $agent;
+ $agentname = $agent->agent;
+ $where .= ' AND cust_main.agentnum = '. $agent->agentnum;
}
-print '
';
-print '