1 <& /elements/header.html, $report->title &>
3 Download full results<BR>
4 as <A HREF="<% $p.'search/report_tax-xls.cgi?'.$cgi->query_string%>">Excel spreadsheet</A>
7 <STYLE type="text/css">
9 background-color: #777777;
14 .grid TH { background-color: #cccccc; padding: 0px 3px 2px }
15 .row0 TD { background-color: #eeeeee; padding: 0px 3px 2px; text-align: right}
16 .row1 TD { background-color: #ffffff; padding: 0px 3px 2px; text-align: right}
17 TD.rowhead { font-weight: bold; text-align: left; padding: 0px 3px }
18 .bigmath { font-size: large; font-weight: bold; font: sans-serif; text-align: center }
19 .total { font-style: italic }
21 <& /elements/table-grid.html &>
25 <TH COLSPAN=5>Sales</TH>
27 <TH ROWSPAN=3>Rate</TH>
29 <TH ROWSPAN=3>Estimated tax</TH>
30 <TH ROWSPAN=3>Tax invoiced</TH>
32 <TH ROWSPAN=3>Tax credited</TH>
34 <TH ROWSPAN=3>Net tax due</TH>
36 <TH ROWSPAN=3>Tax collected</TH>
40 <TH ROWSPAN=2>Total</TH>
41 <TH ROWSPAN=1>Non-taxable</TH>
42 <TH ROWSPAN=1>Non-taxable</TH>
43 <TH ROWSPAN=1>Non-taxable</TH>
44 <TH ROWSPAN=2>Taxable</TH>
47 <TR STYLE="font-size:small">
48 <TH>(tax-exempt customer)</TH>
49 <TH>(tax-exempt package)</TH>
50 <TH>(monthly exemption)</TH>
55 % my $prev_row = { pkgclass => 'DUMMY PKGCLASS' };
58 % foreach my $row (@rows) {
59 % # before anything else: if this row's pkgclass is not the same as the
60 % # previous row's, then:
61 % if ( $row->{pkgclass} ne $prev_row->{pkgclass} ) {
62 % if ( $rownum > 0 ) { # start a new section
66 % if ( $params{breakdown}->{pkgclass} ) { # and caption the new section
68 <TD COLSPAN=19 CLASS="sectionhead">
69 <% $pkgclass_name{$row->{pkgclass}} %>
73 % } # if $row->{pkgclass} ne ...
75 % # construct base links that limit to the tax rates described by this row
76 % my $rowlink = ';taxnum=' . $row->{taxnums};
77 % # and also the package class, if we're limiting package class
78 % if ( $params{breakdown}->{pkgclass} ) {
79 % $rowlink .= ';classnum=' . ($row->{pkgclass} || 0);
82 % if ( $row->{total} ) {
83 </TBODY><TBODY CLASS="total">
85 <TR CLASS="row<% $rownum % 2 %>">
87 <TD CLASS="rowhead"><% $row->{label} |h %></TD>
90 <A HREF="<% $saleslink . $rowlink %>">
91 <% $money_sprintf->( $row->{sales} ) %>
94 % # Exemptions: customer
96 <A HREF="<% $saleslink . $rowlink . ';exempt_cust=Y' %>">
97 <% $money_sprintf->( $row->{exempt_cust} ) %>
102 <A HREF="<% $saleslink . $rowlink . ';exempt_pkg=Y' %>">
103 <% $money_sprintf->( $row->{exempt_pkg} ) %>
106 % # monthly (note this uses $exemptlink; it's a completely separate report)
108 <A HREF="<% $exemptlink . $rowlink %>">
109 <% $money_sprintf->( $row->{exempt_monthly} ) %>
114 <A HREF="<% $saleslink . $rowlink . ";taxable=1" %>">
115 <% $money_sprintf->( $row->{taxable} ) %>
118 <TD CLASS="bigmath"> × </TD>
119 <TD><% $row->{rate} %></TD>
121 <TD CLASS="bigmath"> = </TD>
123 % if ( $row->{estimated} ) {
124 <% $money_sprintf->( $row->{estimated} ) %>
129 <A HREF="<% $taxlink . $rowlink %>">
130 <% $money_sprintf->( $row->{tax} ) %>
134 <TD CLASS="bigmath"> − </TD>
136 %# <A HREF="<% $creditlink . $rowlink %>"> currently broken
137 <% $money_sprintf->( $row->{credit} ) %>
141 <TD CLASS="bigmath"> = </TD>
142 <TD><% $money_sprintf->( $row->{tax} - $row->{credit} ) %></TD>
145 <TD><% $money_sprintf->( $row->{tax_paid} ) %></TD>
149 % } # foreach my $row
150 % # at the end of everything
152 % if ( $report->{outside} > 0 ) {
153 <TBODY CLASS="total" STYLE="background-color: #cccccc; line-height: 3">
156 <% emt('Out of taxable region') %>
158 <TD STYLE="text-align: right">
159 <A HREF="<% $saleslink %>;out=1;taxname=<% encode_entities($params{'taxname'}) %>">
160 <% $money_sprintf->( $report->{outside } ) %>
169 <& /elements/footer.html &>
173 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
175 my $DEBUG = $cgi->param('debug') || 0;
177 my $conf = new FS::Conf;
179 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
182 beginning => $beginning,
185 $params{country} = $cgi->param('country');
186 $params{debug} = $DEBUG;
187 $params{breakdown} = { map { $_ => 1 } $cgi->param('breakdown') };
190 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
191 my $agent = FS::agent->by_key($1) or die "unknown agentnum $1";
192 $params{agentnum} = $1;
193 $agentname = $agent->agentname;
196 # allow anything in here; FS::Report::Tax will treat it as unsafe
197 if ( length($cgi->param('taxname')) ) {
198 $params{taxname} = $cgi->param('taxname');
200 die "taxname required";
203 if ( $cgi->param('credit_date') eq 'cust_credit_bill' ) {
204 $params{credit_date} = 'cust_credit_bill';
206 $params{credit_date} = 'cust_bill';
209 warn "PARAMS:\n".Dumper(\%params)."\n\n" if $DEBUG;
211 my $report = FS::Report::Tax->report_internal(%params);
212 my @rows = $report->table; # array of hashrefs
214 my $money_char = $conf->config('money_char') || '$';
215 my $money_sprintf = sub {
216 $money_char. sprintf('%.2f', shift);
219 my $dateagentlink = "begin=$beginning;end=$ending";
220 if ( $params{agentnum} ) {
221 $dateagentlink .= ';agentnum=' . $params{agentnum};
223 my $saleslink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;nottax=1";
224 my $taxlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;istax=1";
225 my $exemptlink = $p. "search/cust_tax_exempt_pkg.cgi?$dateagentlink";
226 #my $creditlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;credit=1;istax=1";
227 #if ( $params{'credit_date'} eq 'cust_credit_bill' ) {
228 # $creditlink =~ s/begin/credit_begin/;
229 # $creditlink =~ s/end/credit_end/;
231 my $creditlink = ''; # disabled until we find a sane way to do this
233 my %pkgclass_name = map { $_->classnum, $_->classname } qsearch('pkg_class');
234 $pkgclass_name{''} = 'Unclassified';