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, city, taxclass',
15 'count_query' => $count_query,
17 'header2' => \@header2,
21 'cell_style' => \@cell_style,
23 'link_onclicks' => \@link_onclicks,
28 my $conf = new FS::Conf;
29 my $money_char = $conf->config('money_char') || '$';
31 my $exempt_sub = sub {
32 my $cust_main_county = shift;
36 sprintf("$money_char%.2f per month", $cust_main_county->exempt_amount )
37 if $cust_main_county->exempt_amount > 0;
39 push @exempt, 'Setup fee'
40 if $cust_main_county->setuptax =~ /^Y$/i;
42 push @exempt, 'Recurring fee'
43 if $cust_main_county->recurtax =~ /^Y$/i;
45 [ map [ {'data'=>$_} ], @exempt ];
50 my $cell_style_sub = sub {
52 if ( $cs_oldrow ne $row ) {
54 if ( $cs_oldrow->country ne $row->country ) {
55 $cell_style = 'border-top:2px solid #000000';
56 } elsif ( $cs_oldrow->state ne $row->state ) {
57 $cell_style = 'border-top:1px solid #888888';
58 } elsif ( $cs_oldrow->county ne $row->county ) {
59 $cell_style = 'border-top:1px solid #cccccc';
69 #my $edit_link = [ "${p}edit/cust_main_county.html", 'taxnum' ];
70 my $edit_link = [ 'javascript:void(0);', sub { ''; } ];
72 my $edit_onclick = sub {
74 my $taxnum = $row->taxnum;
75 include( '/elements/popup_link_onclick.html',
76 'action' => "${p}edit/cust_main_county.html?$taxnum",
77 'actionlabel' => 'Edit tax rate',
79 #default# 'width' => 540,
80 #default# 'color' => '#333399',
88 if ( $ex_oldrow eq $param{'row'} ) {
91 $ex_oldrow = $param{'row'};
94 my $taxnum = $param{'row'}->taxnum;
95 my $url = "${p}edit/cust_main_county-expand.cgi?$taxnum";
98 include( '/elements/popup_link.html',
99 'label' => $param{'label'},
101 'actionlabel' => $param{'desc'},
103 #default# 'width' => 540,
104 #default# 'color' => '#333399',
112 #if ( $ex_oldrow eq $param{'row'} ) {
115 # $ex_oldrow = $param{'row'};
118 my %below = ( 'county' => 'city',
121 my $what = $below{ $param{'col' } };
123 my $taxnum = $param{'row'}->taxnum;
124 my $url = "${p}edit/cust_main_county-add.cgi?taxnum=$taxnum;what=$what";
127 include( '/elements/popup_link.html',
128 'label' => $param{'label'},
130 'actionlabel' => $param{'desc'},
132 #default# 'width' => 540,
133 #default# 'color' => '#333399',
141 my $row = $param{'row'};
142 my $col = $param{'col'};
144 # if $col eq 'state' and $row->city
146 # 'table' => 'cust_main_county',
148 # 'country' => $row->country,
149 # 'state' => $row->state,
150 # 'city' => { op=>'!=', value=>'' },
152 # 'order_by' => 'LIMIT 1',
155 my %below = ( 'county' => 'city',
159 #XXX can still show the link when you have some counties broken down into
160 #cities and others not :/
162 my $taxnum = $param{'row'}->taxnum;
163 my $url = "${p}edit/process/cust_main_county-collapse.cgi?taxnum=$taxnum;".
164 'country='. uri_escape($cgi->param('country')). ';'.
165 'state='. uri_escape($cgi->param('state')). ';'.
166 'county='. uri_escape($cgi->param('county'));
167 $url = "javascript:collapse_areyousure('$url', '$below{$col}', '$col')";
169 qq(<FONT SIZE="-1"><A HREF="$url">$param{'label'}</A></FONT>);
175 my $row = $param{'row'};
176 my $col = $param{'col'};
178 my $taxnum = $param{'row'}->taxnum;
179 my $url = "${p}edit/process/cust_main_county-remove.cgi?taxnum=$taxnum;".
180 'country='. uri_escape($cgi->param('country')). ';'.
181 'state='. uri_escape($cgi->param('state')). ';'.
182 'county='. uri_escape($cgi->param('county'));
183 $url = "javascript:remove_areyousure('$url', '$col')";
185 qq(<FONT SIZE="-1"><A HREF="$url">$param{'label'}</A></FONT>);
189 sub separate_taxclasses_link {
191 my $taxnum = $row->taxnum;
192 my $url = "${p}edit/process/cust_main_county-expand.cgi?taxclass=1;taxnum=$taxnum";
194 qq!<FONT SIZE="-1"><A HREF="$url">!;
197 #un-separate taxclasses too
203 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
205 #my $conf = new FS::Conf;
206 #my $money_char = $conf->config('money_char') || '$';
207 my $enable_taxclasses = $conf->exists('enable_taxclasses');
211 my $html_init = <<END;
213 function collapse_areyousure(href,col,above) {
214 if (confirm('Are you sure you want to remove all ' + col + ' tax rates for this ' + above + '?') == true)
215 window.location.href = href;
217 function remove_areyousure(href,col) {
218 if (confirm('Are you sure you want to remove this ' + col + '?') == true)
219 window.location.href = href;
224 $html_init .= "<BR>Click on <u>separate taxclasses</u> to specify taxes per taxclass."
225 if $enable_taxclasses;
226 $html_init .= '<BR><BR>';
228 $html_init .= include('/elements/init_overlib.html');
233 if ( $cgi->param('country') =~ /^(\w\w)$/ ) {
237 $cgi->delete('country');
240 if ( $country && $cgi->param('state') =~ /^([\w \-\'\[\]]+)$/ ) {
242 $title = "$state, $title";
244 $cgi->delete('state');
247 if ( $country && $state &&
248 $cgi->param('county') =~
249 /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]+)$/
253 if ( $county eq '__NONE__' ) {
254 $title = "No county, $title";
256 $title = "$county county, $title";
259 $cgi->delete('county');
261 $title = " for $title" if $title;
264 if ( $cgi->param('taxclass') =~ /^([\w \-]+)$/ ) {
266 $title .= " for $taxclass tax class";
268 $cgi->delete('taxclass');
270 if ( $country || $taxclass ) {
271 push @menubar, 'View all tax rates' => $p.'browse/cust_main_county.cgi';
274 $cgi->param('dummy', 1);
277 "window.location = '". $cgi->self_url.
278 ";country=' + encodeURIComponent( document.getElementById('country').options[document.getElementById('country').selectedIndex].value ) + ".
279 "';state=' + encodeURIComponent( document.getElementById('state').options[document.getElementById('state').selectedIndex].value ) +".
280 "';county=' + encodeURIComponent( document.getElementById('county').options[document.getElementById('county').selectedIndex].value );";
282 #restore this so pagination works
283 $cgi->param('country', $country) if $country;
284 $cgi->param('state', $state ) if $state;
285 $cgi->param('county', $county ) if $county;
286 $cgi->param('taxclass', $county ) if $taxclass;
289 '<BR>( show country: '.
290 include('/elements/select-country.html',
291 'country' => $country,
292 'onchange' => $filter_change,
293 'empty_label' => '(all)',
294 'disable_empty' => 0,
295 'disable_stateupdate' => 1,
298 my %states_hash = $country ? states_hash($country) : ();
299 if ( scalar(keys(%states_hash)) > 1 ) {
302 include('/elements/select-state.html',
303 'country' => $country,
305 'onchange' => $filter_change,
306 'empty_label' => '(all)',
307 'disable_empty' => 0,
308 'disable_countyupdate' => 1,
312 '<SELECT NAME="state" ID="state" STYLE="display:none">'.
313 ' <OPTION VALUE="" SELECTED>'.
317 my @counties = ( $country && $state ) ? counties($state, $country) : ();
318 if ( scalar(@counties) > 1 ) {
321 include('/elements/select-county.html',
322 'country' => $country,
325 'onchange' => $filter_change,
326 'empty_label' => '(all)',
327 'empty_data_label' => '(none)',
328 'empty_data_value' => '__NONE__',
329 'disable_empty' => 0,
330 'disable_cityupdate' => 1,
334 '<SELECT NAME="county" ID="county" STYLE="display:none">'.
335 ' <OPTION VALUE="" SELECTED>'.
339 $html_posttotal .= ' )';
341 my $bulk_popup_link =
342 include( '/elements/popup_link_onclick.html',
343 'action' => "${p}edit/bulk-cust_main_county.html?taxnum=MAGIC_taxnum_MAGIC",
344 'actionlabel' => 'Bulk add new tax',
347 #default# 'width' => 540,
348 #default# 'color' => '#333399',
351 my $html_foot = <<END;
352 <SCRIPT TYPE="text/javascript">
354 function setAll(setTo) {
355 theForm = document.taxesForm;
356 for (i=0,n=theForm.elements.length;i<n;i++) {
357 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
358 theForm.elements[i].checked = setTo;
363 function toggleAll() {
364 theForm = document.taxesForm;
365 for (i=0,n=theForm.elements.length;i<n;i++) {
366 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
367 if ( theForm.elements[i].checked == true ) {
368 theForm.elements[i].checked = false;
370 theForm.elements[i].checked = true;
376 function bulkPopup(action) {
377 var bulk_popup_link = "$bulk_popup_link";
379 theForm = document.taxesForm;
380 for (i=0,n=theForm.elements.length;i<n;i++) {
381 if ( theForm.elements[i].name.indexOf("cust_main_county") != -1
382 && theForm.elements[i].checked == true
384 var name = theForm.elements[i].name;
385 var taxnum = name.replace(/cust_main_county/, '');
386 if ( bulkstring != '' ) {
387 bulkstring = bulkstring + ',';
389 bulkstring = bulkstring + taxnum;
393 bulkstring = bulkstring + ';action=' + action;
394 if ( bulk_popup_link.length > 1920 ) { // IE 2083 URL limit
395 alert('Too many selections'); // should do some session thing...
398 bulk_popup_link = bulk_popup_link.replace(/MAGIC_taxnum_MAGIC/, bulkstring);
399 eval(bulk_popup_link);
405 <A HREF="javascript:setAll(true)">select all</A> |
406 <A HREF="javascript:setAll(false)">unselect all</A> |
407 <A HREF="javascript:toggleAll()">toggle all</A>
409 <A HREF="javascript:void(0);" onClick="bulkPopup('add');">Add new tax to selected</A>
411 <A HREF="javascript:void(0);" onClick="bulkPopup('edit');">Bulk edit selected</A>
416 my $count_query = 'SELECT COUNT(*) FROM cust_main_county';
418 $hashref->{'country'} = $country;
419 $count_query .= ' WHERE country = '. dbh->quote($country);
422 $hashref->{'state'} = $state;
423 $count_query .= ' AND state = '. dbh->quote($state);
426 if ( $county eq '__NONE__' ) {
427 $hashref->{'county'} = '';
428 $count_query .= " AND ( county = '' OR county IS NULL ) ";
430 $hashref->{'county'} = $county;
431 $count_query .= ' AND county = '. dbh->quote($county);
435 $hashref->{'taxclass'} = $taxclass;
436 $count_query .= ( $count_query =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
437 ' taxclass = '. dbh->quote($taxclass);
443 my @header = ( 'Country', 'State/Province', 'County', 'City' );
444 my @header2 = ( '', '', '', '', );
445 my @links = ( '', '', '', '', );
446 my @link_onclicks = ( '', '', '', '', );
449 my %seen_country = ();
451 my %seen_county = ();
454 sub { my $country = shift->country;
455 return '' if $seen_country{$country}++;
456 code2country($country). " ($country)";
459 sub { my $label = $seen_state{$_[0]->country}->{$_[0]->state}++
460 ? '' : state_label($_[0]->state, $_[0]->country);
462 my $countylinks = ( $_[0]->county && $label )
463 ? ' '. add_link(
464 desc => 'Add more counties',
466 label=> 'add more counties',
472 label=> 'remove all counties',
481 : ' '. expand_link( desc => 'Add States',
483 label => 'add states',
488 $label.$countylinks.$addlink;
492 $seen_county{$_[0]->country}->{$_[0]->state}->{$_[0]->county}++
493 ? '' : $_[0]->county;
497 $citylinks = $_[0]->city
498 ? ' '. add_link(
499 desc => 'Add more cities',
501 label=> 'add more cities',
507 label=> 'remove all cities',
511 : ' '. remove_link( col => 'county',
512 label=> 'remove county',
521 expand_link( desc => 'Add Counties',
523 label => 'add counties',
529 ? $_[0]->city. ' '.
530 remove_link( col => 'city',
531 label=> 'remove city',
536 expand_link( desc => 'Add Cities',
538 label => 'add cities',
546 sub { shift->state ? '000000' : '999999' },
547 sub { shift->county ? '000000' : '999999' },
548 sub { shift->city ? '000000' : '999999' },
551 if ( $conf->exists('enable_taxclasses') ) {
552 push @header, qq!Tax class (<A HREF="${p}edit/part_pkg_taxclass.html">add new</A>)!;
553 push @header2, '(per-package classification)';
554 push @fields, sub { $_[0]->taxclass || '(all) '.
555 separate_taxclasses_link($_[0], 'Separate Taxclasses').
556 'separate taxclasses</A></FONT>'
558 push @color, sub { shift->taxclass ? '000000' : '999999' };
560 push @link_onclicks, '';
573 '(printed on invoices)',
581 my $cust_main_county = shift;
584 if ( $cb_oldrow->city ne $cust_main_county->city
585 || $cb_oldrow->county ne $cust_main_county->county
586 || $cb_oldrow->state ne $cust_main_county->state
587 || $cb_oldrow->country ne $cust_main_county->country
588 || $cb_oldrow->taxclass ne $cust_main_county->taxclass )
598 $cb_oldrow = $cust_main_county;
601 my $taxnum = $cust_main_county->taxnum;
602 qq!<INPUT NAME="cust_main_county$taxnum" TYPE="checkbox" VALUE="1">!;
610 sub { shift->taxname || 'Tax' },
611 sub { shift->tax. '% <FONT SIZE="-1">(edit)</FONT>' },
617 sub { shift->taxname ? '000000' : '666666' },
618 sub { shift->tax ? '000000' : '666666' },
624 my @cell_style = map $cell_style_sub, (1..scalar(@header));
626 push @links, '', '', $edit_link, '';
627 push @link_onclicks, '', '', $edit_onclick, '';