1 <% include( 'elements/browse.html',
2 'title' => "Tax Rates $title",
3 'name_singular' => 'tax rate',
4 'menubar' => \@menubar,
5 'html_init' => $html_init,
6 'html_posttotal' => $html_posttotal,
8 'table' => 'cust_main_county',
11 'ORDER BY country, state, county, taxclass',
13 'count_query' => $count_query,
15 'header2' => \@header2,
19 'cell_style' => \@cell_style,
21 'link_onclicks' => \@link_onclicks,
25 % # <FONT SIZE=-1><A HREF="<% $p %>edit/process/cust_main_county-collapse.cgi?<% $hashref->{taxnum} %>">collapse state</A></FONT>
30 my $conf = new FS::Conf;
31 my $money_char = $conf->config('money_char') || '$';
33 my @manual_countries = ( 'US', 'CA', 'AU', 'NZ', 'GB' ); #some manual ordering
34 my @all_countries = ( @manual_countries,
35 grep { my $c = $_; ! grep { $c eq $_ } @manual_countries }
38 'select' => 'country',
39 'table' => 'cust_main_county',
41 'extra_sql' => 'GROUP BY country',
45 my $exempt_sub = sub {
46 my $cust_main_county = shift;
50 sprintf("$money_char%.2f per month", $cust_main_county->exempt_amount )
51 if $cust_main_county->exempt_amount > 0;
53 push @exempt, 'Setup fee'
54 if $cust_main_county->setuptax =~ /^Y$/i;
56 push @exempt, 'Recurring fee'
57 if $cust_main_county->recurtax =~ /^Y$/i;
59 [ map [ {'data'=>$_} ], @exempt ];
64 my $cell_style_sub = sub {
66 if ( $oldrow ne $row ) {
68 if ( $oldrow->country ne $row->country ) {
69 $cell_style = 'border-top:1px solid #000000';
70 } elsif ( $oldrow->state ne $row->state ) {
71 $cell_style = 'border-top:1px solid #cccccc'; #default?
72 } elsif ( $oldrow->state eq $row->state ) {
73 #$cell_style = 'border-top:dashed 1px dark gray';
74 $cell_style = 'border-top:1px dashed #cccccc';
82 #my $edit_link = [ "${p}edit/cust_main_county.html", 'taxnum' ];
83 my $edit_link = [ 'javascript:void(0);', sub { ''; } ];
85 my $edit_onclick = sub {
87 my $taxnum = $row->taxnum;
88 include( '/elements/popup_link_onclick.html',
89 'action' => "${p}edit/cust_main_county.html?$taxnum",
90 'actionlabel' => 'Edit tax rate',
92 #default# 'width' => 540,
93 #default# 'color' => '#333399',
100 my $taxnum = $param{'row'}->taxnum;
101 my $url = "${p}edit/cust_main_county-expand.cgi?$taxnum";
104 include( '/elements/popup_link.html',
105 'label' => $param{'label'},
107 'actionlabel' => $param{'desc'},
109 #default# 'width' => 540,
110 #default# 'color' => '#333399',
115 sub separate_taxclasses_link {
117 my $taxnum = $row->taxnum;
118 my $url = "${p}edit/process/cust_main_county-expand.cgi?taxclass=1;taxnum=$taxnum";
120 qq!<FONT SIZE="-1"><A HREF="$url">!;
127 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
129 #my $conf = new FS::Conf;
130 #my $money_char = $conf->config('money_char') || '$';
131 my $enable_taxclasses = $conf->exists('enable_taxclasses');
136 "Click on <u>add states</u> to specify a country's tax rates by state or province.
137 <BR>Click on <u>add counties</u> to specify a state's tax rates by county.";
138 $html_init .= "<BR>Click on <u>separate taxclasses</u> to specify taxes per taxclass."
139 if $enable_taxclasses;
140 $html_init .= '<BR><BR>';
142 $html_init .= include('/elements/init_overlib.html');
147 if ( $cgi->param('country') =~ /^(\w\w)$/ ) {
151 $cgi->delete('country');
154 if ( $cgi->param('state') =~ /^([\w \-\'\[\]]+)$/ ) {
156 $title = "$state, $title";
158 $cgi->delete('state');
161 if ( $cgi->param('county') =~ /^([\w \-\'\[\]]+)$/ ) {
163 $title = "$county county, $title";
165 $cgi->delete('county');
167 $title = " for $title" if $title;
170 if ( $cgi->param('taxclass') =~ /^([\w \-]+)$/ ) {
172 $title .= " for $taxclass tax class";
174 $cgi->delete('taxclass');
176 if ( $country || $taxclass ) {
177 push @menubar, 'View all tax rates' => $p.'browse/cust_main_county.cgi';
180 $cgi->param('dummy', 1);
182 my $country_filter_change =
183 "window.location = '".
184 $cgi->self_url. ";country=' + this.options[this.selectedIndex].value;";
186 #restore this so pagination works
187 $cgi->param('country', $country) if $country;
188 $cgi->param('state', $state ) if $state;
189 $cgi->param('county', $county ) if $county;
190 $cgi->param('taxclass', $county ) if $taxclass;
194 qq(<SELECT NAME="country" onChange="$country_filter_change">).
195 qq(<OPTION VALUE="">(all)\n).
196 join("\n", map qq[<OPTION VALUE="$_"].
197 ( $_ eq $country ? 'SELECTED' : '' ).
198 '>'. code2country($_). " ($_)",
204 my $count_query = 'SELECT COUNT(*) FROM cust_main_county';
206 $hashref->{'country'} = $country;
207 $count_query .= ' WHERE country = '. dbh->quote($country);
210 $hashref->{'state'} = $state;
211 $count_query .= ' AND state = '. dbh->quote($state);
214 $hashref->{'country'} = $country;
215 $count_query .= ' AND county = '. dbh->quote($county);
218 $hashref->{'taxclass'} = $taxclass;
219 $count_query .= ( $count_query =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
220 ' taxclass = '. dbh->quote($taxclass);
226 my @header = ( 'Country', 'State/Province', 'County',);
227 my @header2 = ( '', '', '', );
228 my @links = ( '', '', '', );
229 my @link_onclicks = ( '', '', '', );
233 sub { my $country = shift->country;
234 code2country($country). " ($country)";
236 sub { state_label($_[0]->state, $_[0]->country).
239 : ' '. expand_link( desc => 'Add States',
241 label => 'add states',
245 sub { $_[0]->county || '(all) '.
246 expand_link( desc => 'Add Counties',
248 label => 'add counties',
255 sub { shift->state ? '000000' : '999999' },
256 sub { shift->county ? '000000' : '999999' },
259 if ( $conf->exists('enable_taxclasses') ) {
260 push @header, qq!Tax class (<A HREF="${p}edit/part_pkg_taxclass.html">add new</A>)!;
261 push @header2, '(per-package classification)';
262 push @fields, sub { $_[0]->taxclass || '(all) '.
263 separate_taxclasses_link($_[0], 'Separate Taxclasses').
264 'separate taxclasses</A></FONT>'
266 push @color, sub { shift->taxclass ? '000000' : '999999' };
268 push @link_onclicks, '';
272 push @header, 'Tax name',
277 push @header2, '(printed on invoices)',
283 sub { shift->taxname || 'Tax' },
284 sub { shift->tax. '% <FONT SIZE="-1">(edit)</FONT>' },
289 sub { shift->taxname ? '000000' : '666666' },
290 sub { shift->tax ? '000000' : '666666' },
296 my @cell_style = map $cell_style_sub, (1..scalar(@header));
298 push @links, '', $edit_link, '';
299 push @link_onclicks, '', $edit_onclick, '';