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>';
143 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws.js"></SCRIPT>
144 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws_iframe.js"></SCRIPT>
145 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws_draggable.js"></SCRIPT>
146 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/iframecontentmws.js"></SCRIPT>
152 if ( $cgi->param('country') =~ /^(\w\w)$/ ) {
156 $cgi->delete('country');
159 if ( $cgi->param('state') =~ /^([\w \-\'\[\]]+)$/ ) {
161 $title = "$state, $title";
163 $cgi->delete('state');
166 if ( $cgi->param('county') =~ /^([\w \-\'\[\]]+)$/ ) {
168 $title = "$county county, $title";
170 $cgi->delete('county');
172 $title = " for $title" if $title;
175 if ( $cgi->param('taxclass') =~ /^([\w \-]+)$/ ) {
177 $title .= " for $taxclass tax class";
179 $cgi->delete('taxclass');
181 if ( $country || $taxclass ) {
182 push @menubar, 'View all tax rates' => $p.'browse/cust_main_county.cgi';
185 $cgi->param('dummy', 1);
187 my $country_filter_change =
188 "window.location = '".
189 $cgi->self_url. ";country=' + this.options[this.selectedIndex].value;";
191 #restore this so pagination works
192 $cgi->param('country', $country) if $country;
193 $cgi->param('state', $state ) if $state;
194 $cgi->param('county', $county ) if $county;
195 $cgi->param('taxclass', $county ) if $taxclass;
199 qq(<SELECT NAME="country" onChange="$country_filter_change">).
200 qq(<OPTION VALUE="">(all)\n).
201 join("\n", map qq[<OPTION VALUE="$_"].
202 ( $_ eq $country ? 'SELECTED' : '' ).
203 '>'. code2country($_). " ($_)",
209 my $count_query = 'SELECT COUNT(*) FROM cust_main_county';
211 $hashref->{'country'} = $country;
212 $count_query .= ' WHERE country = '. dbh->quote($country);
215 $hashref->{'state'} = $state;
216 $count_query .= ' AND state = '. dbh->quote($state);
219 $hashref->{'country'} = $country;
220 $count_query .= ' AND county = '. dbh->quote($county);
223 $hashref->{'taxclass'} = $taxclass;
224 $count_query .= ( $count_query =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
225 ' taxclass = '. dbh->quote($taxclass);
231 my @header = ( 'Country', 'State/Province', 'County',);
232 my @header2 = ( '', '', '', );
233 my @links = ( '', '', '', );
234 my @link_onclicks = ( '', '', '', );
238 sub { my $country = shift->country;
239 code2country($country). " ($country)";
241 sub { state_label($_[0]->state, $_[0]->country).
244 : ' '. expand_link( desc => 'Add States',
246 label => 'add states',
250 sub { $_[0]->county || '(all) '.
251 expand_link( desc => 'Add Counties',
253 label => 'add counties',
260 sub { shift->state ? '000000' : '999999' },
261 sub { shift->county ? '000000' : '999999' },
264 if ( $conf->exists('enable_taxclasses') ) {
265 push @header, qq!Tax class (<A HREF="${p}edit/part_pkg_taxclass.html">add new</A>)!;
266 push @header2, '(per-package classification)';
267 push @fields, sub { $_[0]->taxclass || '(all) '.
268 separate_taxclasses_link($_[0], 'Separate Taxclasses').
269 'separate taxclasses</A></FONT>'
271 push @color, sub { shift->taxclass ? '000000' : '999999' };
273 push @link_onclicks, '';
277 push @header, 'Tax name',
282 push @header2, '(printed on invoices)',
288 sub { shift->taxname || 'Tax' },
289 sub { shift->tax. '% <FONT SIZE="-1">(edit)</FONT>' },
294 sub { shift->taxname ? '000000' : '666666' },
295 sub { shift->tax ? '000000' : '666666' },
301 my @cell_style = map $cell_style_sub, (1..scalar(@header));
303 push @links, '', $edit_link, '';
304 push @link_onclicks, '', $edit_onclick, '';