X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Freport_tax.cgi;h=4de733c239102334179f690908df2cd139245738;hb=61e4d4c2bbb146090aa3acd1f31fd9f109d17425;hp=bedfdac5feff4995b5c4eb413e506dcaa2e6c0d5;hpb=cefb9727ed4cdfacf3b967485d58b25fbea98c6b;p=freeside.git
diff --git a/httemplate/search/report_tax.cgi b/httemplate/search/report_tax.cgi
old mode 100755
new mode 100644
index bedfdac5f..83f2fc5d3
--- a/httemplate/search/report_tax.cgi
+++ b/httemplate/search/report_tax.cgi
@@ -1,35 +1,230 @@
-<%
+<& /elements/header.html, $report->title &>
+
+Download full results
+as Excel spreadsheet
+ |
-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 );
+
+<& /elements/table-grid.html &>
+
+
+ |
+ Sales |
+ |
+ Rate |
+ |
+ Estimated tax |
+ Tax invoiced |
+ |
+ Tax credited |
+ |
+ Net tax due |
+
+
+
+ Total |
+ Non-taxable |
+ Non-taxable |
+ Non-taxable |
+ Taxable |
+
+
+
+ (tax-exempt customer) |
+ (tax-exempt package) |
+ (monthly exemption) |
+
+
+
+% my $rownum = 0;
+% my $prev_row = { pkgclass => 'DUMMY PKGCLASS' };
+
+
+% foreach my $row (@rows) {
+% # before anything else: if this row's pkgclass is not the same as the
+% # previous row's, then:
+% if ( $row->{pkgclass} ne $prev_row->{pkgclass} ) {
+% if ( $rownum > 0 ) { # start a new section
+% $rownum = 0;
+
+% }
+% if ( $params{breakdown}->{pkgclass} ) { # and caption the new section
+
+
+ <% $pkgclass_name{$row->{pkgclass}} %>
+ |
+
+% }
+% } # if $row->{pkgclass} ne ...
+
+% # construct base links that limit to the tax rates described by this row
+% my $rowlink = ';taxnum=' . $row->{taxnums};
+% # and also the package class, if we're limiting package class
+% if ( $params{breakdown}->{pkgclass} ) {
+% $rowlink .= ';classnum=' . ($row->{pkgclass} || 0);
+% }
+%
+% if ( $row->{total} ) {
+
+% }
+
+% # Row label
+ <% $row->{label} |h %> |
+
+% # Total sales
+
+ <% $money_sprintf->( $row->{sales} ) %>
+
+ |
+% # Exemptions: customer
+
+
+ <% $money_sprintf->( $row->{exempt_cust} ) %>
+
+ |
+% # package
+
+
+ <% $money_sprintf->( $row->{exempt_pkg} ) %>
+
+ |
+% # monthly (note this uses $exemptlink; it's a completely separate report)
+
+
+ <% $money_sprintf->( $row->{exempt_monthly} ) %>
+
+ |
+% # taxable sales
+
+ ">
+ <% $money_sprintf->( $row->{taxable} ) %>
+
+ |
+ × |
+ <% $row->{rate} %> |
+% # estimated tax
+ = |
+
+% if ( $row->{estimated} ) {
+ <% $money_sprintf->( $row->{estimated} ) %>
+% }
+ |
+% # invoiced tax
+
+
+ <% $money_sprintf->( $row->{tax} ) %>
+
+ |
+% # credited tax
+ − |
+
+
+ <% $money_sprintf->( $row->{credit} ) %>
+
+ |
+% # net tax due
+ = |
+ <% $money_sprintf->( $row->{tax} - $row->{credit} ) %> |
+
+% $rownum++;
+% $prev_row = $row;
+% } # foreach my $row
+% # at the end of everything
+
+% if ( $report->{outside} > 0 ) {
+
+
+
+ <% emt('Out of taxable region') %>
+ |
+
+
+ <% $money_sprintf->( $report->{outside } ) %>
+
+ |
+ |
+
+
+% }
+
+
+<& /elements/footer.html &>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
-$cgi = new CGI;
-&cgisuidsetup($cgi);
+my $DEBUG = $cgi->param('debug') || 0;
-$user = getotaker;
+my $conf = new FS::Conf;
-$cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/;
-$beginning = $1;
+my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
-$cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/;
-$ending = $1;
+my %params = (
+ beginning => $beginning,
+ ending => $ending,
+);
+$params{country} = $cgi->param('country');
+$params{debug} = $DEBUG;
+$params{breakdown} = { map { $_ => 1 } $cgi->param('breakdown') };
-print $cgi->header( '-expires' => '-2m' ),
- header('Tax Report Results');
+my $agentname;
+if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
+ my $agent = FS::agent->by_key($1) or die "unknown agentnum $1";
+ $params{agentnum} = $1;
+ $agentname = $agent->agentname;
+}
+
+if ( $cgi->param('taxname') =~ /^([\w ]+)$/ ) {
+ $params{taxname} = $1;
+} else {
+ die "taxname required";
+}
+
+if ( $cgi->param('credit_date') eq 'cust_credit_bill' ) {
+ $params{credit_date} = 'cust_credit_bill';
+} else {
+ $params{credit_date} = 'cust_bill';
+}
+
+warn "PARAMS:\n".Dumper(\%params)."\n\n" if $DEBUG;
-open (REPORT, "/usr/bin/freeside-tax-report -v -s $beginning -d $ending $user |");
+my $report = FS::Report::Tax->report_internal(%params);
+my @rows = $report->table; # array of hashrefs
-print '';
-while() {
- print $_;
+my $money_char = $conf->config('money_char') || '$';
+my $money_sprintf = sub {
+ $money_char. sprintf('%.2f', shift);
+};
+
+my $dateagentlink = "begin=$beginning;end=$ending";
+if ( $params{agentnum} ) {
+ $dateagentlink .= ';agentnum=' . $params{agentnum};
}
-print '
';
+my $saleslink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;nottax=1";
+my $taxlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;istax=1";
+my $exemptlink = $p. "search/cust_tax_exempt_pkg.cgi?$dateagentlink";
+my $creditlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;credit=1;istax=1";
-print '