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 % my $rowregion = ';country=' . $cgi->param('country');
82 % foreach my $loc (qw(state county city district)) {
83 % if ( $row->{$loc} ) {
84 % $rowregion .= ";$loc=" . uri_escape($row->{$loc});
87 % # and also the package class, if we're limiting package class
88 % if ( $params{breakdown}->{pkgclass} ) {
89 % $rowlink .= ';classnum=' . ($row->{pkgclass} || 0);
90 % $rowregion .= ';classnum=' . ($row->{pkgclass} || 0);
93 % if ( $row->{total} ) {
94 </TBODY><TBODY CLASS="total">
96 <TR CLASS="row<% $rownum % 2 %>">
98 <TD CLASS="rowhead"><% $row->{label} |h %></TD>
101 <A HREF="<% $saleslink . $rowlink %>">
102 <% $money_sprintf->( $row->{sales} ) %>
105 % # Exemptions: customer
107 <A HREF="<% $saleslink . $rowlink . ';exempt_cust=Y' %>">
108 <% $money_sprintf->( $row->{exempt_cust} ) %>
113 <A HREF="<% $saleslink . $rowlink . ';exempt_pkg=Y' %>">
114 <% $money_sprintf->( $row->{exempt_pkg} ) %>
117 % # monthly (note this uses $exemptlink; it's a completely separate report)
119 <A HREF="<% $exemptlink . $rowlink %>">
120 <% $money_sprintf->( $row->{exempt_monthly} ) %>
125 <A HREF="<% $salescreditlink . $rowregion %>">
126 <% $money_sprintf->( $row->{sales_credited} ) %>
131 <A HREF="<% $saleslink . $rowlink . ";taxable=1" %>">
132 <% $money_sprintf->( $row->{taxable} ) %>
135 <TD CLASS="bigmath"> × </TD>
136 <TD><% $row->{rate} %></TD>
138 <TD CLASS="bigmath"> = </TD>
140 % if ( $row->{estimated} ) {
141 <% $money_sprintf->( $row->{estimated} ) %>
146 <A HREF="<% $taxlink . $rowlink %>">
147 <% $money_sprintf->( $row->{tax} ) %>
151 <TD CLASS="bigmath"> − </TD>
153 %# <A HREF="<% $creditlink . $rowlink %>"> currently broken
154 <% $money_sprintf->( $row->{tax_credited} ) %>
158 <TD CLASS="bigmath"> = </TD>
159 <TD><% $money_sprintf->( $row->{tax} - $row->{tax_credited} ) %></TD>
162 <TD><% $money_sprintf->( $row->{tax_paid} ) %></TD>
166 % } # foreach my $row
167 % # at the end of everything
169 % if ( $report->{outside} > 0 ) {
170 <TBODY CLASS="total" STYLE="background-color: #cccccc; line-height: 3">
173 <% emt('Out of taxable region') %>
175 <TD STYLE="text-align: right">
176 <A HREF="<% $saleslink %>;out=1;taxname=<% encode_entities($params{'taxname'}) %>">
177 <% $money_sprintf->( $report->{outside } ) %>
187 <& /elements/table-grid.html &>
191 <TH ROWSPAN=2>Total credits</TH>
192 <TH COLSPAN=3>Applied to</TH>
194 <TR STYLE="font-size: small">
195 <TH>Taxable sales</TH>
196 <TH>Tax-exempt sales</TH>
202 % $prev_row = { pkgclass => 'DUMMY PKGCLASS' };
205 % # mostly duplicates the stuff above...
206 % # but putting it all in one giant table is no good
207 % foreach my $row (@rows) {
208 % if ( $row->{pkgclass} ne $prev_row->{pkgclass} ) {
209 % if ( $rownum > 0 ) { # start a new section
213 % if ( $params{breakdown}->{pkgclass} ) { # and caption the new section
215 <TD COLSPAN=5 CLASS="sectionhead">
216 <% $pkgclass_name{$row->{pkgclass}} %>
220 % } # if $row->{pkgclass} ne ...
222 % my $rowlink = ';taxnum=' . $row->{taxnums};
223 % my $rowregion = ';country=' . $cgi->param('country');
224 % foreach my $loc (qw(state county city district)) {
225 % if ( $row->{$loc} ) {
226 % $rowregion .= ";$loc=" . uri_escape($row->{$loc});
229 % if ( $params{breakdown}->{pkgclass} ) {
230 % $rowlink .= ';classnum=' . ($row->{pkgclass} || 0);
231 % $rowregion .= ';classnum=' . ($row->{pkgclass} || 0);
234 % if ( $row->{total} ) {
235 </TBODY><TBODY CLASS="total">
237 <TR CLASS="row<% $rownum % 2 %>">
238 <TD CLASS="rowhead"><% $row->{label} |h %></TD>
241 <% $money_sprintf->( $row->{credits} ) %>
243 % # Credits to taxable sales
245 <A HREF="<% $salescreditlink . $rowregion %>">
246 <% $money_sprintf->( $row->{sales_credited} ) %>
249 % # ... to exempt sales (link is the same, it shows both exempt and taxable)
251 <A HREF="<% $salescreditlink . $rowregion %>">
252 <% $money_sprintf->( $row->{exempt_credited} ) %>
257 %# <A HREF="<% $creditlink . $rowlink %>"> currently broken
258 <% $money_sprintf->( $row->{tax_credited} ) %>
264 % } # foreach my $row
265 % # no "out of taxable region" for credits (yet)
270 <& /elements/footer.html &>
274 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
276 my $DEBUG = $cgi->param('debug') || 0;
278 my $conf = new FS::Conf;
280 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
283 beginning => $beginning,
286 $params{country} = $cgi->param('country');
287 $params{debug} = $DEBUG;
288 $params{breakdown} = { map { $_ => 1 } $cgi->param('breakdown') };
291 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
292 my $agent = FS::agent->by_key($1) or die "unknown agentnum $1";
293 $params{agentnum} = $1;
294 $agentname = $agent->agentname;
297 # allow anything in here; FS::Report::Tax will treat it as unsafe
298 if ( length($cgi->param('taxname')) ) {
299 $params{taxname} = $cgi->param('taxname');
301 die "taxname required";
304 if ( $cgi->param('credit_date') eq 'cust_credit_bill' ) {
305 $params{credit_date} = 'cust_credit_bill';
307 $params{credit_date} = 'cust_bill';
310 warn "PARAMS:\n".Dumper(\%params)."\n\n" if $DEBUG;
312 my $report = FS::Report::Tax->report_internal(%params);
313 my @rows = $report->table; # array of hashrefs
315 my $money_char = $conf->config('money_char') || '$';
316 my $money_sprintf = sub {
317 $money_char. sprintf('%.2f', shift);
320 my $dateagentlink = "begin=$beginning;end=$ending";
321 if ( $params{agentnum} ) {
322 $dateagentlink .= ';agentnum=' . $params{agentnum};
324 my $saleslink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;nottax=1";
325 my $taxlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;istax=1";
326 my $exemptlink = $p. "search/cust_tax_exempt_pkg.cgi?$dateagentlink";
327 my $salescreditlink = $p. "search/cust_credit_bill_pkg.html?$dateagentlink;nottax=1";
328 if ( $params{'credit_date'} eq 'cust_credit_bill' ) {
329 $salescreditlink =~ s/begin/credit_begin/;
330 $salescreditlink =~ s/end/credit_end/;
332 #my $creditlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;credit=1;istax=1";
333 #if ( $params{'credit_date'} eq 'cust_credit_bill' ) {
334 # $creditlink =~ s/begin/credit_begin/;
335 # $creditlink =~ s/end/credit_end/;
337 my $creditlink = ''; # disabled until we find a sane way to do this
339 my %pkgclass_name = map { $_->classnum, $_->classname } qsearch('pkg_class');
340 $pkgclass_name{''} = 'Unclassified';