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 }
22 <& /elements/table-grid.html &>
26 <TH COLSPAN=6>Sales</TH>
28 <TH ROWSPAN=3>Rate</TH>
30 <TH ROWSPAN=3>Estimated tax</TH>
31 <TH ROWSPAN=3>Tax invoiced</TH>
33 <TH ROWSPAN=3>Tax credited</TH>
35 <TH ROWSPAN=3>Net tax due</TH>
37 <TH ROWSPAN=3>Tax collected</TH>
41 <TH ROWSPAN=2>Total</TH>
42 <TH ROWSPAN=1>Non-taxable</TH>
43 <TH ROWSPAN=1>Non-taxable</TH>
44 <TH ROWSPAN=1>Non-taxable</TH>
45 <TH ROWSPAN=2>Credited</TH>
46 <TH ROWSPAN=2>Taxable</TH>
49 <TR STYLE="font-size:small">
50 <TH>(tax-exempt customer)</TH>
51 <TH>(tax-exempt package)</TH>
52 <TH>(monthly exemption)</TH>
57 % my $prev_row = { pkgclass => 'DUMMY PKGCLASS' };
60 % foreach my $row (@rows) {
61 % # before anything else: if this row's pkgclass is not the same as the
62 % # previous row's, then:
63 % if ( $row->{pkgclass} ne $prev_row->{pkgclass} ) {
64 % if ( $rownum > 0 ) { # start a new section
68 % if ( $params{breakdown}->{pkgclass} ) { # and caption the new section
70 <TD COLSPAN=19 CLASS="sectionhead">
71 <% $pkgclass_name{$row->{pkgclass}} %>
75 % } # if $row->{pkgclass} ne ...
77 % # construct base links that limit to the tax rates described by this row
78 % # cust_bill_pkg.cgi wants a list of specific taxnums (and package class)
79 % # cust_credit_bill_pkg.html wants a geographic scope (and package class)
80 % my $rowlink = ';taxnum=' . $row->{taxnums};
81 % if ( $params{breakdown}->{pkgclass} ) {
82 % $rowlink .= ';classnum=' . ($row->{pkgclass} || 0);
83 % # $rowregion .= ';classnum=' . ($row->{pkgclass} || 0);
86 % if ( $row->{total} ) {
87 </TBODY><TBODY CLASS="total">
89 <TR CLASS="row<% $rownum % 2 %>">
91 % # Special: If this report is showing all taxes, link the row label to
92 % # the detailed tax report for that taxname/country.
95 % my $newcgi = CGI->new($cgi);
96 % $newcgi->delete('all');
97 % $newcgi->param('country', $row->{country});
98 % $newcgi->param('taxname', $row->{taxname});
99 % $newcgi->param('breakdown', qw(city district));
101 <A HREF="<% encode_entities( $newcgi->self_url ) %>">
102 <% $row->{label} |h %>
105 % } else { # on the per-taxname report, just show the label with no link
107 <% $row->{label} |h %>
113 <A HREF="<% $saleslink . $rowlink %>">
114 <% $money_sprintf->( $row->{sales} ) %>
117 % # Exemptions: customer
119 <A HREF="<% $saleslink . $rowlink . ';exempt_cust=Y' %>">
120 <% $money_sprintf->( $row->{exempt_cust} ) %>
125 <A HREF="<% $saleslink . $rowlink . ';exempt_pkg=Y' %>">
126 <% $money_sprintf->( $row->{exempt_pkg} ) %>
129 % # monthly (note this uses $exemptlink; it's a completely separate report)
131 <A HREF="<% $exemptlink . $rowlink %>">
132 <% $money_sprintf->( $row->{exempt_monthly} ) %>
137 <A HREF="<% $salescreditlink . $rowlink %>">
138 <% $money_sprintf->( $row->{sales_credited} ) %>
143 <A HREF="<% $saleslink . $rowlink . ";taxable=1" %>">
144 <% $money_sprintf->( $row->{taxable} ) %>
147 <TD CLASS="bigmath"> × </TD>
148 <TD><% $row->{rate} %></TD>
150 <TD CLASS="bigmath"> = </TD>
152 % if ( $row->{estimated} ) {
153 <% $money_sprintf->( $row->{estimated} ) %>
158 <A HREF="<% $taxlink . $rowlink %>">
159 <% $money_sprintf->( $row->{tax} ) %>
163 <TD CLASS="bigmath"> − </TD>
165 %# <A HREF="<% $creditlink . $rowlink %>"> currently broken
166 <% $money_sprintf->( $row->{tax_credited} ) %>
170 <TD CLASS="bigmath"> = </TD>
171 <TD><% $money_sprintf->( $row->{tax} - $row->{tax_credited} ) %></TD>
174 <TD><% $money_sprintf->( $row->{tax_paid} ) %></TD>
178 % } # foreach my $row
179 % # at the end of everything
181 % # the all-taxes report doesn't have "out of region"
182 % if ( !$all and $report->{out_sales} > 0 ) {
183 <TBODY CLASS="total" STYLE="background-color: #cccccc; line-height: 3">
186 <% emt('Out of taxable region') %>
188 <TD STYLE="text-align: right">
189 <A HREF="<% $saleslink %>;out=1;taxname=<% encode_entities($params{'taxname'}) %>">
190 <% $money_sprintf->( $report->{out_sales} ) %>
200 <& /elements/table-grid.html &>
204 <TH ROWSPAN=2>Total credits</TH>
205 <TH COLSPAN=3>Applied to</TH>
207 <TR STYLE="font-size: small">
208 <TH>Taxable sales</TH>
209 <TH>Tax-exempt sales</TH>
215 % $prev_row = { pkgclass => 'DUMMY PKGCLASS' };
218 % # mostly duplicates the stuff above...
219 % # but putting it all in one giant table is no good
220 % foreach my $row (@rows) {
221 % if ( $row->{pkgclass} ne $prev_row->{pkgclass} ) {
222 % if ( $rownum > 0 ) { # start a new section
226 % if ( $params{breakdown}->{pkgclass} ) { # and caption the new section
228 <TD COLSPAN=5 CLASS="sectionhead">
229 <% $pkgclass_name{$row->{pkgclass}} %>
233 % } # if $row->{pkgclass} ne ...
235 % my $rowlink = ';taxnum=' . $row->{taxnums};
237 % if ( $row->{total} ) {
238 </TBODY><TBODY CLASS="total">
240 <TR CLASS="row<% $rownum % 2 %>">
241 <TD CLASS="rowhead"><% $row->{label} |h %></TD>
244 <% $money_sprintf->( $row->{credits} ) %>
246 % # Credits to taxable sales
248 <A HREF="<% $salescreditlink . $rowlink %>">
249 <% $money_sprintf->( $row->{sales_credited} ) %>
252 % # ... to exempt sales (link is the same, it shows both exempt and taxable)
254 <A HREF="<% $salescreditlink . $rowlink %>">
255 <% $money_sprintf->( $row->{exempt_credited} ) %>
260 %# <A HREF="<% $creditlink . $rowlink %>"> currently broken
261 <% $money_sprintf->( $row->{tax_credited} ) %>
267 % } # foreach my $row
268 % # "out of taxable region" for credits (there is a need for it)
269 % if ( !$all and $report->{out_credit} > 0 ) {
270 % my $creditlink = "cust_credit_bill_pkg.html?out=1;$dateagentlink";
271 % if ( $params{'credit_date'} eq 'cust_credit_bill' ) {
272 % $creditlink =~ s/begin/credit_begin/;
273 % $creditlink =~ s/end/credit_end/;
275 % $creditlink .= ";taxname=" . encode_entities($params{'taxname'});
276 <TBODY CLASS="total" STYLE="background-color: #cccccc; line-height: 3">
279 <% emt('Out of taxable region') %>
281 <TD STYLE="text-align: right">
282 <A HREF="<% $creditlink %>">
283 <% $money_sprintf->( $report->{out_credit} ) %>
294 <& /elements/footer.html &>
298 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
300 my $DEBUG = $cgi->param('debug') || 0;
302 my $conf = new FS::Conf;
304 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
307 beginning => $beginning,
310 $params{debug} = $DEBUG;
314 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
315 my $agent = FS::agent->by_key($1) or die "unknown agentnum $1";
316 $params{agentnum} = $1;
317 $agentname = $agent->agentname;
320 # credit date behavior: limit by the date of the credit application, or
322 if ( $cgi->param('credit_date') eq 'cust_credit_bill' ) {
323 $params{credit_date} = 'cust_credit_bill';
325 $params{credit_date} = 'cust_bill';
328 my $all = $cgi->param('all');
332 # then show the master report, no country, no taxname, no breakdown
333 $report_class = 'FS::Report::Tax::All';
335 $report_class = 'FS::Report::Tax::ByName';
336 $params{country} = $cgi->param('country');
337 $params{breakdown} = { map { $_ => 1 } $cgi->param('breakdown') };
339 # allow anything in here; FS::Report::Tax will treat it as unsafe
340 if ( length($cgi->param('taxname')) ) {
341 $params{taxname} = $cgi->param('taxname');
343 die "taxname required";
348 warn "REPORT: $report_class\nPARAMS:\n".Dumper(\%params)."\n\n";
351 my $report = $report_class->report(%params);
352 my @rows = $report->table; # array of hashrefs
354 my $money_char = $conf->config('money_char') || '$';
355 my $money_sprintf = sub {
356 $money_char. sprintf('%.2f', shift);
359 my $dateagentlink = "begin=$beginning;end=$ending";
360 if ( $params{agentnum} ) {
361 $dateagentlink .= ';agentnum=' . $params{agentnum};
363 my $saleslink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;nottax=1";
364 my $taxlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;istax=1";
365 my $exemptlink = $p. "search/cust_tax_exempt_pkg.cgi?$dateagentlink";
366 my $salescreditlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;nottax=1;credit=1";
367 if ( $params{'credit_date'} eq 'cust_credit_bill' ) {
368 $salescreditlink =~ s/begin/credit_begin/;
369 $salescreditlink =~ s/end/credit_end/;
370 $saleslink .= ";credit_begin=$beginning;credit_end=$ending";
372 #my $creditlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;credit=1;istax=1";
373 #if ( $params{'credit_date'} eq 'cust_credit_bill' ) {
374 # $creditlink =~ s/begin/credit_begin/;
375 # $creditlink =~ s/end/credit_end/;
377 my $creditlink = ''; # disabled until we find a sane way to do this
379 my %pkgclass_name = map { $_->classnum, $_->classname } qsearch('pkg_class');
380 $pkgclass_name{''} = 'Unclassified';