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 my $color = '#333399';
89 qq!overlib( OLiframeContent('${p}edit/cust_main_county.html?$taxnum', 540, 420, 'edit_cust_main_county_popup' ), CAPTION, 'Edit tax rate', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '$color', CGCOLOR, '$color' ); return false;!;
93 my( $row, $desc ) = @_;
94 my $taxnum = $row->taxnum;
95 my $url = "${p}edit/cust_main_county-expand.cgi?$taxnum";
96 my $color = '#333399';
98 qq!<FONT SIZE="-1"><A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('$url', 540, 420, 'edit_cust_main_county_popup' ), CAPTION, '$desc', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '$color', CGCOLOR, '$color' ); return false;">!;
101 sub separate_taxclasses_link {
103 my $taxnum = $row->taxnum;
104 my $url = "${p}edit/process/cust_main_county-expand.cgi?taxclass=1;taxnum=$taxnum";
106 qq!<FONT SIZE="-1"><A HREF="$url">!;
113 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
115 #my $conf = new FS::Conf;
116 #my $money_char = $conf->config('money_char') || '$';
117 my $enable_taxclasses = $conf->exists('enable_taxclasses');
122 "Click on <u>add states</u> to specify a country's tax rates by state or province.
123 <BR>Click on <u>add counties</u> to specify a state's tax rates by county.";
124 $html_init .= "<BR>Click on <u>separate taxclasses</u> to specify taxes per taxclass."
125 if $enable_taxclasses;
126 $html_init .= '<BR><BR>';
129 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws.js"></SCRIPT>
130 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws_iframe.js"></SCRIPT>
131 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/overlibmws_draggable.js"></SCRIPT>
132 <SCRIPT TYPE="text/javascript" SRC="${fsurl}elements/iframecontentmws.js"></SCRIPT>
138 if ( $cgi->param('country') =~ /^(\w\w)$/ ) {
142 $cgi->delete('country');
145 if ( $cgi->param('state') =~ /^([\w \-\'\[\]]+)$/ ) {
147 $title = "$state, $title";
149 $cgi->delete('state');
152 if ( $cgi->param('county') =~ /^([\w \-\'\[\]]+)$/ ) {
154 $title = "$county county, $title";
156 $cgi->delete('county');
158 $title = " for $title" if $title;
161 if ( $cgi->param('taxclass') =~ /^([\w \-]+)$/ ) {
163 $title .= " for $taxclass tax class";
165 $cgi->delete('taxclass');
167 if ( $country || $taxclass ) {
168 push @menubar, 'View all tax rates' => $p.'browse/cust_main_county.cgi';
171 $cgi->param('dummy', 1);
173 my $country_filter_change =
174 "window.location = '".
175 $cgi->self_url. ";country=' + this.options[this.selectedIndex].value;";
177 #restore this so pagination works
178 $cgi->param('country', $country) if $country;
179 $cgi->param('state', $state ) if $state;
180 $cgi->param('county', $county ) if $county;
181 $cgi->param('taxclass', $county ) if $taxclass;
185 qq(<SELECT NAME="country" onChange="$country_filter_change">).
186 qq(<OPTION VALUE="">(all)\n).
187 join("\n", map qq[<OPTION VALUE="$_"].
188 ( $_ eq $country ? 'SELECTED' : '' ).
189 '>'. code2country($_). " ($_)",
195 my $count_query = 'SELECT COUNT(*) FROM cust_main_county';
197 $hashref->{'country'} = $country;
198 $count_query .= ' WHERE country = '. dbh->quote($country);
201 $hashref->{'state'} = $state;
202 $count_query .= ' AND state = '. dbh->quote($state);
205 $hashref->{'country'} = $country;
206 $count_query .= ' AND county = '. dbh->quote($county);
209 $hashref->{'taxclass'} = $taxclass;
210 $count_query .= ( $count_query =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
211 ' taxclass = '. dbh->quote($taxclass);
217 my @header = ( 'Country', 'State/Province', 'County',);
218 my @header2 = ( '', '', '', );
219 my @links = ( '', '', '', );
220 my @link_onclicks = ( '', '', '', );
224 sub { my $country = shift->country;
225 code2country($country). " ($country)";
227 sub { state_label($_[0]->state, $_[0]->country).
230 : ' '. expand_link($_[0], 'Add States').
231 'add states</A></FONT>'
234 sub { $_[0]->county || '(all) '.
235 expand_link($_[0], 'Add Counties').
236 'add counties</A></FONT>'
242 sub { shift->state ? '000000' : '999999' },
243 sub { shift->county ? '000000' : '999999' },
246 if ( $conf->exists('enable_taxclasses') ) {
247 push @header, qq!Tax class (<A HREF="${p}edit/part_pkg_taxclass.html">add new</A>)!;
248 push @header2, '(per-package classification)';
249 push @fields, sub { $_[0]->taxclass || '(all) '.
250 separate_taxclasses_link($_[0], 'Separate Taxclasses').
251 'separate taxclasses</A></FONT>'
253 push @color, sub { shift->taxclass ? '000000' : '999999' };
255 push @link_onclicks, '';
259 push @header, 'Tax name',
264 push @header2, '(printed on invoices)',
270 sub { shift->taxname || 'Tax' },
271 sub { shift->tax. '% <FONT SIZE="-1">(edit)</FONT>' },
276 sub { shift->taxname ? '000000' : '666666' },
277 sub { shift->tax ? '000000' : '666666' },
283 my @cell_style = map $cell_style_sub, (1..scalar(@header));
285 push @links, '', $edit_link, '';
286 push @link_onclicks, '', $edit_onclick, '';