1 package FS::Report::Tax::All;
5 use FS::Record qw(dbh qsearch qsearchs group_concat_sql);
6 use FS::Report::Tax::ByName;
7 use Date::Format qw( time2str );
15 Constructor. Generates a tax report using the internal tax rate system,
16 showing all taxes, broken down by tax name and country.
19 - beginning, ending: the date range as Unix timestamps.
22 - debug: sets the debug level. 1 will warn the data collected for the report;
23 2 will also warn all of the SQL statements.
27 # because there's not yet a "DBIx::DBSchema::View"...
33 $DEBUG ||= $opt{debug};
35 my($beginning, $ending) = @opt{'beginning', 'ending'};
37 # figure out which reports we need to run
38 my @taxname_and_country = qsearch({
39 table => 'cust_main_county',
40 select => 'country, taxname',
42 tax => { op => '>', value => '0' }
44 order_by => 'GROUP BY country, taxname ORDER BY country, taxname',
47 foreach (@taxname_and_country) {
48 my $taxname = $_->taxname || 'Tax';
49 my $country = $_->country;
50 my $report = FS::Report::Tax::ByName->report(
56 # will have only one total row (should be only one row at all)
57 my ($total_row) = grep { $_->{total} } $report->table;
58 $total_row->{total} = 0; # but in this context it's a detail row
59 $total_row->{taxname} = $taxname;
60 $total_row->{country} = $country;
61 $total_row->{label} = "$country - $taxname";
62 push @table, $total_row;
82 # sub fetchall_array...
92 if ( $self->{opt}->{agentnum} ) {
93 my $agent = qsearchs('agent', { agentnum => $self->{opt}->{agentnum} });
94 $string .= $agent->agent . ' ';
96 $string .= 'Tax Report: '; # XXX localization
97 if ( $self->{opt}->{beginning} ) {
98 $string .= time2str('%h %o %Y ', $self->{opt}->{beginning});
100 $string .= 'through ';
101 if ( $self->{opt}->{ending} and $self->{opt}->{ending} < 4294967295 ) {
102 $string .= time2str('%h %o %Y', $self->{opt}->{ending});
106 $string .= ' - all taxes';