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>
38 <TH ROWSPAN=2>Total</TH>
39 <TH ROWSPAN=1>Non-taxable</TH>
40 <TH ROWSPAN=1>Non-taxable</TH>
41 <TH ROWSPAN=1>Non-taxable</TH>
42 <TH ROWSPAN=2>Taxable</TH>
45 <TR STYLE="font-size:small">
46 <TH>(tax-exempt customer)</TH>
47 <TH>(tax-exempt package)</TH>
48 <TH>(monthly exemption)</TH>
53 % my $prev_row = { pkgclass => 'DUMMY PKGCLASS' };
56 % foreach my $row (@rows) {
57 % # before anything else: if this row's pkgclass is not the same as the
58 % # previous row's, then:
59 % if ( $row->{pkgclass} ne $prev_row->{pkgclass} ) {
60 % if ( $rownum > 0 ) { # start a new section
64 % if ( $params{breakdown}->{pkgclass} ) { # and caption the new section
66 <TD COLSPAN=19 CLASS="sectionhead">
67 <% $pkgclass_name{$row->{pkgclass}} %>
71 % } # if $row->{pkgclass} ne ...
73 % # construct base links that limit to the tax rates described by this row
74 % my $rowlink = ';taxnum=' . $row->{taxnums};
75 % # and also the package class, if we're limiting package class
76 % if ( $params{breakdown}->{pkgclass} ) {
77 % $rowlink .= ';classnum=' . ($row->{pkgclass} || 0);
80 % if ( $row->{total} ) {
81 </TBODY><TBODY CLASS="total">
83 <TR CLASS="row<% $rownum % 2 %>">
85 <TD CLASS="rowhead"><% $row->{label} |h %></TD>
88 <A HREF="<% $saleslink . $rowlink %>">
89 <% $money_sprintf->( $row->{sales} ) %>
92 % # Exemptions: customer
94 <A HREF="<% $saleslink . $rowlink . ';exempt_cust=Y' %>">
95 <% $money_sprintf->( $row->{exempt_cust} ) %>
100 <A HREF="<% $saleslink . $rowlink . ';exempt_pkg=Y' %>">
101 <% $money_sprintf->( $row->{exempt_pkg} ) %>
104 % # monthly (note this uses $exemptlink; it's a completely separate report)
106 <A HREF="<% $exemptlink . $rowlink %>">
107 <% $money_sprintf->( $row->{exempt_monthly} ) %>
112 <A HREF="<% $saleslink . $rowlink . ";taxable=1" %>">
113 <% $money_sprintf->( $row->{taxable} ) %>
116 <TD CLASS="bigmath"> × </TD>
117 <TD><% $row->{rate} %></TD>
119 <TD CLASS="bigmath"> = </TD>
121 % if ( $row->{estimated} ) {
122 <% $money_sprintf->( $row->{estimated} ) %>
127 <A HREF="<% $taxlink . $rowlink %>">
128 <% $money_sprintf->( $row->{tax} ) %>
132 <TD CLASS="bigmath"> − </TD>
134 <A HREF="<% $creditlink . $rowlink %>">
135 <% $money_sprintf->( $row->{credit} ) %>
139 <TD CLASS="bigmath"> = </TD>
140 <TD><% $money_sprintf->( $row->{tax} - $row->{credit} ) %></TD>
144 % } # foreach my $row
145 % # at the end of everything
147 % if ( $report->{outside} > 0 ) {
148 <TBODY CLASS="total" STYLE="background-color: #cccccc; line-height: 3">
151 <% emt('Out of taxable region') %>
153 <TD STYLE="text-align: right">
154 <A HREF="<% $saleslink %>;out=1;taxname=<% encode_entities($params{'taxname'}) %>">
155 <% $money_sprintf->( $report->{outside } ) %>
164 <& /elements/footer.html &>
168 unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
170 my $DEBUG = $cgi->param('debug') || 0;
172 my $conf = new FS::Conf;
174 my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
177 beginning => $beginning,
180 $params{country} = $cgi->param('country');
181 $params{debug} = $DEBUG;
182 $params{breakdown} = { map { $_ => 1 } $cgi->param('breakdown') };
185 if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
186 my $agent = FS::agent->by_key($1) or die "unknown agentnum $1";
187 $params{agentnum} = $1;
188 $agentname = $agent->agentname;
191 # allow anything in here; FS::Report::Tax will treat it as unsafe
192 if ( length($cgi->param('taxname')) ) {
193 $params{taxname} = $cgi->param('taxname');
195 die "taxname required";
198 if ( $cgi->param('credit_date') eq 'cust_credit_bill' ) {
199 $params{credit_date} = 'cust_credit_bill';
201 $params{credit_date} = 'cust_bill';
204 warn "PARAMS:\n".Dumper(\%params)."\n\n" if $DEBUG;
206 my $report = FS::Report::Tax->report_internal(%params);
207 my @rows = $report->table; # array of hashrefs
209 my $money_char = $conf->config('money_char') || '$';
210 my $money_sprintf = sub {
211 $money_char. sprintf('%.2f', shift);
214 my $dateagentlink = "begin=$beginning;end=$ending";
215 if ( $params{agentnum} ) {
216 $dateagentlink .= ';agentnum=' . $params{agentnum};
218 my $saleslink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;nottax=1";
219 my $taxlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;istax=1";
220 my $exemptlink = $p. "search/cust_tax_exempt_pkg.cgi?$dateagentlink";
221 my $creditlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;credit=1;istax=1";
223 if ( $params{'credit_date'} eq 'cust_credit_bill' ) {
224 $creditlink =~ s/begin/credit_begin/;
225 $creditlink =~ s/end/credit_end/;
228 my %pkgclass_name = map { $_->classnum, $_->classname } qsearch('pkg_class');
229 $pkgclass_name{''} = 'Unclassified';