<& /elements/header.html, $report->title &> Download full results
as Excel spreadsheet <& /elements/table-grid.html &> Sales Rate Estimated tax Tax invoiced Tax credited Net tax due Tax collected Total Non-taxable Non-taxable Non-taxable Credited Taxable (tax-exempt customer) (tax-exempt package) (monthly exemption) % my $rownum = 0; % my $prev_row = { pkgclass => 'DUMMY PKGCLASS' }; % foreach my $row (@rows) { % # before anything else: if this row's pkgclass is not the same as the % # previous row's, then: % if ( $row->{pkgclass} ne $prev_row->{pkgclass} ) { % if ( $rownum > 0 ) { # start a new section % $rownum = 0; % } % if ( $params{breakdown}->{pkgclass} ) { # and caption the new section <% $pkgclass_name{$row->{pkgclass}} %> % } % } # if $row->{pkgclass} ne ... % # construct base links that limit to the tax rates described by this row % # cust_bill_pkg.cgi wants a list of specific taxnums (and package class) % # cust_credit_bill_pkg.html wants a geographic scope (and package class) % my $rowlink = ';taxnum=' . $row->{taxnums}; % my $rowregion = ''; % foreach my $loc (qw(state county city district)) { % if ( $row->{$loc} ) { % $rowregion .= ";$loc=" . uri_escape($row->{$loc}); % } % } % # and also the package class, if we're limiting package class % if ( $params{breakdown}->{pkgclass} ) { % $rowlink .= ';classnum=' . ($row->{pkgclass} || 0); % $rowregion .= ';classnum=' . ($row->{pkgclass} || 0); % } % % if ( $row->{total} ) { % } % # Row label <% $row->{label} |h %> % # Total sales <% $money_sprintf->( $row->{sales} ) %> % # Exemptions: customer <% $money_sprintf->( $row->{exempt_cust} ) %> % # package <% $money_sprintf->( $row->{exempt_pkg} ) %> % # monthly (note this uses $exemptlink; it's a completely separate report) <% $money_sprintf->( $row->{exempt_monthly} ) %> % # credited sales <% $money_sprintf->( $row->{sales_credited} ) %> % # taxable sales "> <% $money_sprintf->( $row->{taxable} ) %> × <% $row->{rate} %> % # estimated tax = % if ( $row->{estimated} ) { <% $money_sprintf->( $row->{estimated} ) %> % } % # invoiced tax <% $money_sprintf->( $row->{tax} ) %> % # credited tax − %# currently broken <% $money_sprintf->( $row->{tax_credited} ) %> %# % # net tax due = <% $money_sprintf->( $row->{tax} - $row->{tax_credited} ) %> % # tax collected   <% $money_sprintf->( $row->{tax_paid} ) %> % $rownum++; % $prev_row = $row; % } # foreach my $row % # at the end of everything % if ( $report->{outside} > 0 ) { <% emt('Out of taxable region') %> <% $money_sprintf->( $report->{outside } ) %> % } <& /elements/footer.html &> <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Financial reports'); my $DEBUG = $cgi->param('debug') || 0; my $conf = new FS::Conf; my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi); my %params = ( beginning => $beginning, ending => $ending, ); $params{country} = $cgi->param('country'); $params{debug} = $DEBUG; $params{breakdown} = { map { $_ => 1 } $cgi->param('breakdown') }; my $agentname; if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { my $agent = FS::agent->by_key($1) or die "unknown agentnum $1"; $params{agentnum} = $1; $agentname = $agent->agentname; } # allow anything in here; FS::Report::Tax will treat it as unsafe if ( length($cgi->param('taxname')) ) { $params{taxname} = $cgi->param('taxname'); } else { die "taxname required"; } if ( $cgi->param('credit_date') eq 'cust_credit_bill' ) { $params{credit_date} = 'cust_credit_bill'; } else { $params{credit_date} = 'cust_bill'; } warn "PARAMS:\n".Dumper(\%params)."\n\n" if $DEBUG; my $report = FS::Report::Tax->report_internal(%params); my @rows = $report->table; # array of hashrefs my $money_char = $conf->config('money_char') || '$'; my $money_sprintf = sub { $money_char. sprintf('%.2f', shift); }; my $dateagentlink = "begin=$beginning;end=$ending"; if ( $params{agentnum} ) { $dateagentlink .= ';agentnum=' . $params{agentnum}; } my $saleslink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;nottax=1"; my $taxlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;istax=1"; my $exemptlink = $p. "search/cust_tax_exempt_pkg.cgi?$dateagentlink"; my $salescreditlink = $p. "search/cust_credit_bill_pkg.html?$dateagentlink;nottax=1"; if ( $params{'credit_date'} eq 'cust_credit_bill' ) { $salescreditlink =~ s/begin/credit_begin/; $salescreditlink =~ s/end/credit_end/; } #my $creditlink = $p. "search/cust_bill_pkg.cgi?$dateagentlink;credit=1;istax=1"; #if ( $params{'credit_date'} eq 'cust_credit_bill' ) { # $creditlink =~ s/begin/credit_begin/; # $creditlink =~ s/end/credit_end/; #} my $creditlink = ''; # disabled until we find a sane way to do this my %pkgclass_name = map { $_->classnum, $_->classname } qsearch('pkg_class'); $pkgclass_name{''} = 'Unclassified';