X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Freport_tax.cgi;h=7eb07cf3ce08f47764f36f30bf02d144c856d1cd;hb=6397a30ca9f53c90a503da8786925ec75535a699;hp=bedfdac5feff4995b5c4eb413e506dcaa2e6c0d5;hpb=cefb9727ed4cdfacf3b967485d58b25fbea98c6b;p=freeside.git
diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi
index bedfdac5f..7eb07cf3c 100755
--- a/httemplate/search/report_tax.cgi
+++ b/httemplate/search/report_tax.cgi
@@ -1,35 +1,579 @@
-<%
+<% 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') %>
+
+
+ |
+ Sales |
+ |
+ Rate |
+ |
+ Tax owed |
+% unless ( $cgi->param('show_taxclasses') ) {
+ Tax invoiced |
+% }
+
+
+
+ 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'} ne 'Total' ) {
+% if ( $region->{'label'} eq $out ) {
+% $link = ';out=1';
+% } else {
+% $link = ';'. $region->{'url_param'};
+% }
+% }
+%
+% if ( $bgcolor eq $bgcolor1 ) {
+% $bgcolor = $bgcolor2;
+% } else {
+% $bgcolor = $bgcolor1;
+% }
+%
+% my $td = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
+% 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" %>
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $region->{'owed'} ) %>
+
+
+% unless ( $cgi->param('show_taxclasses') ) {
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $region->{'tax'} ) %>
+
+% }
+
+
+% }
+
+
+
+% if ( $cgi->param('show_taxclasses') ) {
+
+
+ <% include('/elements/table-grid.html') %>
+
+ |
+ Tax invoiced |
+
+
+% #some false laziness w/above
+% $bgcolor1 = '#eeeeee';
+% $bgcolor2 = '#ffffff';
+%
+% foreach my $region ( @base_regions ) {
+%
+% my $link = '';
+% #if ( $region->{'label'} ne 'Total' ) {
+% if ( $region->{'label'} eq $out ) {
+% $link = ';out=1';
+% } else {
+% $link = ';'. $region->{'url_param'};
+% }
+% #}
+%
+% if ( $bgcolor eq $bgcolor1 ) {
+% $bgcolor = $bgcolor2;
+% } else {
+% $bgcolor = $bgcolor1;
+% }
+% my $td = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
+
+
+ <<%$td%>><% $region->{'label'} %>
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $region->{'tax'} ) %>
+
+
-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);
+% if ( $bgcolor eq $bgcolor1 ) {
+% $bgcolor = $bgcolor2;
+% } else {
+% $bgcolor = $bgcolor1;
+% }
+% my $td = qq(TD CLASS="grid" BGCOLOR="$bgcolor");
-$user = getotaker;
+
+ <<%$td%>>Total
+ <<%$td%> ALIGN="right">
+ <% &$money_sprintf( $tax ) %>
+
+
-$cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/;
-$beginning = $1;
+
-$cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/;
-$ending = $1;
+% }
-print $cgi->header( '-expires' => '-2m' ),
- header('Tax Report Results');
+<% include('/elements/footer.html') %>
-open (REPORT, "/usr/bin/freeside-tax-report -v -s $beginning -d $ending $user |");
+<%init>
-print '';
-while() {
- print $_;
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+
+my $conf = new FS::Conf;
+
+my $user = getotaker;
+
+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 '