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=6>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>Credited</TH>
45 <TH ROWSPAN=2>Taxable</TH>
48 <TR STYLE="font-size:small">
49 <TH>(tax-exempt customer)</TH>
50 <TH>(tax-exempt package)</TH>
51 <TH>(monthly exemption)</TH>
56 % my $prev_row = { pkgclass => 'DUMMY PKGCLASS' };
59 % foreach my $row (@rows) {
60 % # before anything else: if this row's pkgclass is not the same as the
61 % # previous row's, then:
62 % if ( $row->{pkgclass} ne $prev_row->{pkgclass} ) {
63 % if ( $rownum > 0 ) { # start a new section
67 % if ( $params{breakdown}->{pkgclass} ) { # and caption the new section
69 <TD COLSPAN=19 CLASS="sectionhead">
70 <% $pkgclass_name{$row->{pkgclass}} %>
74 % } # if $row->{pkgclass} ne ...
76 % # construct base links that limit to the tax rates described by this row
77 % # cust_bill_pkg.cgi wants a list of specific taxnums (and package class)
78 % # cust_credit_bill_pkg.html wants a geographic scope (and package class)
79 % my $rowlink = ';taxnum=' . $row->{taxnums};
81 % foreach my $loc (qw(state county city district)) {
82 % if ( $row->{$loc} ) {
83 % $rowregion .= ";$loc=" . uri_escape($row->{$loc});
86 % # and also the package class, if we're limiting package class
87 % if ( $params{breakdown}->{pkgclass} ) {
88 % $rowlink .= ';classnum=' . ($row->{pkgclass} || 0);
89 % $rowregion .= ';classnum=' . ($row->{pkgclass} || 0);
92 % if ( $row->{total} ) {
93 </TBODY><TBODY CLASS="total">
95 <TR CLASS="row<% $rownum % 2 %>">
97 <TD CLASS="rowhead"><% $row->{label} |h %></TD>
100 <A HREF="<% $saleslink . $rowlink %>">
101 <% $money_sprintf->( $row->{sales} ) %>
104 % # Exemptions: customer
106 <A HREF="<% $saleslink . $rowlink . ';exempt_cust=Y' %>">
107 <% $money_sprintf->( $row->{exempt_cust} ) %>
112 <A HREF="<% $saleslink . $rowlink . ';exempt_pkg=Y' %>">
113 <% $money_sprintf->( $row->{exempt_pkg} ) %>
116 % # monthly (note this uses $exemptlink; it's a completely separate report)
118 <A HREF="<% $exemptlink . $rowlink %>">
119 <% $money_sprintf->( $row->{exempt_monthly} ) %>
124 <A HREF="<% $salescreditlink . $rowregion %>">
125 <% $money_sprintf->( $row->{sales_credited} ) %>
130 <A HREF="<% $saleslink . $rowlink . ";taxable=1" %>">
131 <% $money_sprintf->( $row->{taxable} ) %>
134 <TD CLASS="bigmath"> × </TD>
135 <TD><% $row->{rate} %></TD>
137 <TD CLASS="bigmath"> = </TD>
139 % if ( $row->{estimated} ) {
140 <% $money_sprintf->( $row->{estimated} ) %>
145 <A HREF="<% $taxlink . $rowlink %>">
146 <% $money_sprintf->( $row->{tax} ) %>
150 <TD CLASS="bigmath"> − </TD>
152 %# <A HREF="<% $creditlink . $rowlink %>"> currently broken
153 <% $money_sprintf->( $row->{tax_credited} ) %>
157 <TD CLASS="bigmath"> = </TD>
158 <TD><% $money_sprintf->( $row->{tax} - $row->{tax_credited} ) %></TD>
161 <TD><% $money_sprintf->( $row->{tax_paid} ) %></TD>
165 % } # foreach my $row
166 % # at the end of everything
168 % if ( $report->{outside} > 0 ) {
169 <TBODY CLASS="total" STYLE="background-color: #cccccc; line-height: 3">
172 <% emt('Out of taxable region') %>
174 <TD STYLE="text-align: right">
175 <A HREF="<% $saleslink %>;out=1;taxname=<% encode_entities($params{'taxname'}) %>">
176 <% $money_sprintf->( $report->{outside } ) %>
185 <& /elements/footer.html &>
189 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
191 my $DEBUG = $cgi->param('debug') || 0;
193 my $conf = new FS::Conf;
195 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
198 beginning => $beginning,
201 $params{country} = $cgi->param('country');
202 $params{debug} = $DEBUG;
203 $params{breakdown} = { map { $_ => 1 } $cgi->param('breakdown') };
206 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
207 my $agent = FS::agent->by_key($1) or die "unknown agentnum $1";
208 $params{agentnum} = $1;
209 $agentname = $agent->agentname;
212 # allow anything in here; FS::Report::Tax will treat it as unsafe
213 if ( length($cgi->param('taxname')) ) {
214 $params{taxname} = $cgi->param('taxname');
216 die "taxname required";
219 if ( $cgi->param('credit_date') eq 'cust_credit_bill' ) {
220 $params{credit_date} = 'cust_credit_bill';
222 $params{credit_date} = 'cust_bill';
225 warn "PARAMS:\n".Dumper(\%params)."\n\n" if $DEBUG;
227 my $report = FS::Report::Tax->report_internal(%params);
228 my @rows = $report->table; # array of hashrefs
230 my $money_char = $conf->config('money_char') || '$';
231 my $money_sprintf = sub {
232 $money_char. sprintf('%.2f', shift);
235 my $dateagentlink = "begin=$beginning;end=$ending";
236 if ( $params{agentnum} ) {
237 $dateagentlink .= ';agentnum=' . $params{agentnum};
239 my $saleslink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;nottax=1";
240 my $taxlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;istax=1";
241 my $exemptlink = $p. "search/cust_tax_exempt_pkg.cgi?$dateagentlink";
242 my $salescreditlink = $p. "search/cust_credit_bill_pkg.html?$dateagentlink;nottax=1";
243 if ( $params{'credit_date'} eq 'cust_credit_bill' ) {
244 $salescreditlink =~ s/begin/credit_begin/;
245 $salescreditlink =~ s/end/credit_end/;
247 #my $creditlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;credit=1;istax=1";
248 #if ( $params{'credit_date'} eq 'cust_credit_bill' ) {
249 # $creditlink =~ s/begin/credit_begin/;
250 # $creditlink =~ s/end/credit_end/;
252 my $creditlink = ''; # disabled until we find a sane way to do this
254 my %pkgclass_name = map { $_->classnum, $_->classname } qsearch('pkg_class');
255 $pkgclass_name{''} = 'Unclassified';