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,
7 'html_form' => '<FORM NAME="taxesForm">',
8 'html_foot' => $html_foot,
10 'table' => 'cust_main_county',
11 'hashref' => $hashref,
13 'ORDER BY country, state, county, taxclass',
15 'count_query' => $count_query,
17 'header2' => \@header2,
21 'cell_style' => \@cell_style,
23 'link_onclicks' => \@link_onclicks,
27 % # <FONT SIZE=-1><A HREF="<% $p %>edit/process/cust_main_county-collapse.cgi?<% $hashref->{taxnum} %>">collapse state</A></FONT>
32 my $conf = new FS::Conf;
33 my $money_char = $conf->config('money_char') || '$';
35 my @manual_countries = ( 'US', 'CA', 'AU', 'NZ', 'GB' ); #some manual ordering
36 my @all_countries = ( @manual_countries,
37 grep { my $c = $_; ! grep { $c eq $_ } @manual_countries }
40 'select' => 'country',
41 'table' => 'cust_main_county',
43 'extra_sql' => 'GROUP BY country',
47 my $exempt_sub = sub {
48 my $cust_main_county = shift;
52 sprintf("$money_char%.2f per month", $cust_main_county->exempt_amount )
53 if $cust_main_county->exempt_amount > 0;
55 push @exempt, 'Setup fee'
56 if $cust_main_county->setuptax =~ /^Y$/i;
58 push @exempt, 'Recurring fee'
59 if $cust_main_county->recurtax =~ /^Y$/i;
61 [ map [ {'data'=>$_} ], @exempt ];
66 my $cell_style_sub = sub {
68 if ( $oldrow ne $row ) {
70 if ( $oldrow->country ne $row->country ) {
71 $cell_style = 'border-top:1px solid #000000';
72 } elsif ( $oldrow->state ne $row->state ) {
73 $cell_style = 'border-top:1px solid #cccccc'; #default?
74 } elsif ( $oldrow->state eq $row->state ) {
75 #$cell_style = 'border-top:dashed 1px dark gray';
76 $cell_style = 'border-top:1px dashed #cccccc';
84 #my $edit_link = [ "${p}edit/cust_main_county.html", 'taxnum' ];
85 my $edit_link = [ 'javascript:void(0);', sub { ''; } ];
87 my $edit_onclick = sub {
89 my $taxnum = $row->taxnum;
90 include( '/elements/popup_link_onclick.html',
91 'action' => "${p}edit/cust_main_county.html?$taxnum",
92 'actionlabel' => 'Edit tax rate',
94 #default# 'width' => 540,
95 #default# 'color' => '#333399',
102 my $taxnum = $param{'row'}->taxnum;
103 my $url = "${p}edit/cust_main_county-expand.cgi?$taxnum";
106 include( '/elements/popup_link.html',
107 'label' => $param{'label'},
109 'actionlabel' => $param{'desc'},
111 #default# 'width' => 540,
112 #default# 'color' => '#333399',
117 sub separate_taxclasses_link {
119 my $taxnum = $row->taxnum;
120 my $url = "${p}edit/process/cust_main_county-expand.cgi?taxclass=1;taxnum=$taxnum";
122 qq!<FONT SIZE="-1"><A HREF="$url">!;
129 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
131 #my $conf = new FS::Conf;
132 #my $money_char = $conf->config('money_char') || '$';
133 my $enable_taxclasses = $conf->exists('enable_taxclasses');
138 "Click on <u>add states</u> to specify a country's tax rates by state or province.
139 <BR>Click on <u>add counties</u> to specify a state's tax rates by county.";
140 $html_init .= "<BR>Click on <u>separate taxclasses</u> to specify taxes per taxclass."
141 if $enable_taxclasses;
142 $html_init .= '<BR><BR>';
144 $html_init .= include('/elements/init_overlib.html');
149 if ( $cgi->param('country') =~ /^(\w\w)$/ ) {
153 $cgi->delete('country');
156 if ( $cgi->param('state') =~ /^([\w \-\'\[\]]+)$/ ) {
158 $title = "$state, $title";
160 $cgi->delete('state');
163 if ( $cgi->param('county') =~ /^([\w \-\'\[\]]+)$/ ) {
165 $title = "$county county, $title";
167 $cgi->delete('county');
169 $title = " for $title" if $title;
172 if ( $cgi->param('taxclass') =~ /^([\w \-]+)$/ ) {
174 $title .= " for $taxclass tax class";
176 $cgi->delete('taxclass');
178 if ( $country || $taxclass ) {
179 push @menubar, 'View all tax rates' => $p.'browse/cust_main_county.cgi';
182 $cgi->param('dummy', 1);
184 my $country_filter_change =
185 "window.location = '".
186 $cgi->self_url. ";country=' + this.options[this.selectedIndex].value;";
188 #restore this so pagination works
189 $cgi->param('country', $country) if $country;
190 $cgi->param('state', $state ) if $state;
191 $cgi->param('county', $county ) if $county;
192 $cgi->param('taxclass', $county ) if $taxclass;
196 qq(<SELECT NAME="country" onChange="$country_filter_change">).
197 qq(<OPTION VALUE="">(all)\n).
198 join("\n", map qq[<OPTION VALUE="$_"].
199 ( $_ eq $country ? 'SELECTED' : '' ).
200 '>'. code2country($_). " ($_)",
205 my $bulk_popup_link =
206 include( '/elements/popup_link_onclick.html',
207 'action' => "${p}edit/bulk-cust_main_county.html?MAGIC_taxnum_MAGIC",
208 'actionlabel' => 'Bulk add new tax',
211 #default# 'width' => 540,
212 #default# 'color' => '#333399',
215 my $html_foot = <<END;
216 <SCRIPT TYPE="text/javascript">
218 function setAll(setTo) {
219 theForm = document.taxesForm;
220 for (i=0,n=theForm.elements.length;i<n;i++) {
221 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
222 theForm.elements[i].checked = setTo;
227 function toggleAll() {
228 theForm = document.taxesForm;
229 for (i=0,n=theForm.elements.length;i<n;i++) {
230 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
231 if ( theForm.elements[i].checked == true ) {
232 theForm.elements[i].checked = false;
234 theForm.elements[i].checked = true;
240 function bulkPopup() {
241 var bulk_popup_link = "$bulk_popup_link";
243 theForm = document.taxesForm;
244 for (i=0,n=theForm.elements.length;i<n;i++) {
245 if ( theForm.elements[i].name.indexOf("cust_main_county") != -1
246 && theForm.elements[i].checked == true
248 var name = theForm.elements[i].name;
249 var taxnum = name.replace(/cust_main_county/, '');
250 if ( bulkstring != '' ) {
251 bulkstring = bulkstring + ',';
253 bulkstring = bulkstring + taxnum;
257 if ( bulk_popup_link.length > 1920 ) { // IE 2083 URL limit
258 alert('Too many selections'); // should do some session thing...
261 bulk_popup_link = bulk_popup_link.replace(/MAGIC_taxnum_MAGIC/, bulkstring);
262 eval(bulk_popup_link);
268 <A HREF="javascript:setAll(true)">select all</A> |
269 <A HREF="javascript:setAll(false)">unselect all</A> |
270 <A HREF="javascript:toggleAll()">toggle all</A>
272 <A HREF="javascript:void(0);" onClick="bulkPopup();">Add new tax to selected</A>
277 my $count_query = 'SELECT COUNT(*) FROM cust_main_county';
279 $hashref->{'country'} = $country;
280 $count_query .= ' WHERE country = '. dbh->quote($country);
283 $hashref->{'state'} = $state;
284 $count_query .= ' AND state = '. dbh->quote($state);
287 $hashref->{'country'} = $country;
288 $count_query .= ' AND county = '. dbh->quote($county);
291 $hashref->{'taxclass'} = $taxclass;
292 $count_query .= ( $count_query =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
293 ' taxclass = '. dbh->quote($taxclass);
299 my @header = ( 'Country', 'State/Province', 'County',);
300 my @header2 = ( '', '', '', );
301 my @links = ( '', '', '', );
302 my @link_onclicks = ( '', '', '', );
306 sub { my $country = shift->country;
307 code2country($country). " ($country)";
309 sub { state_label($_[0]->state, $_[0]->country).
312 : ' '. expand_link( desc => 'Add States',
314 label => 'add states',
318 sub { $_[0]->county || '(all) '.
319 expand_link( desc => 'Add Counties',
321 label => 'add counties',
328 sub { shift->state ? '000000' : '999999' },
329 sub { shift->county ? '000000' : '999999' },
332 if ( $conf->exists('enable_taxclasses') ) {
333 push @header, qq!Tax class (<A HREF="${p}edit/part_pkg_taxclass.html">add new</A>)!;
334 push @header2, '(per-package classification)';
335 push @fields, sub { $_[0]->taxclass || '(all) '.
336 separate_taxclasses_link($_[0], 'Separate Taxclasses').
337 'separate taxclasses</A></FONT>'
339 push @color, sub { shift->taxclass ? '000000' : '999999' };
341 push @link_onclicks, '';
354 '(printed on invoices)',
362 my $cust_main_county = shift;
365 if ( $cb_oldrow->country ne $cust_main_county->country
366 || $cb_oldrow->state ne $cust_main_county->state
367 || $cb_oldrow->county ne $cust_main_county->county
368 || $cb_oldrow->taxclass ne $cust_main_county->taxclass )
378 $cb_oldrow = $cust_main_county;
381 my $taxnum = $cust_main_county->taxnum;
382 qq!<INPUT NAME="cust_main_county$taxnum" TYPE="checkbox" VALUE="1">!;
390 sub { shift->taxname || 'Tax' },
391 sub { shift->tax. '% <FONT SIZE="-1">(edit)</FONT>' },
397 sub { shift->taxname ? '000000' : '666666' },
398 sub { shift->tax ? '000000' : '666666' },
404 my @cell_style = map $cell_style_sub, (1..scalar(@header));
406 push @links, '', '', $edit_link, '';
407 push @link_onclicks, '', '', $edit_onclick, '';