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 #cccccc'; #default?
58 $cell_style = 'border-top:1px solid #bbbbbb';
59 } elsif ( $cs_oldrow->state eq $row->state ) {
60 #$cell_style = 'border-top:dashed 1px dark gray';
61 #$cell_style = 'border-top:1px dashed #cccccc';
70 #my $edit_link = [ "${p}edit/cust_main_county.html", 'taxnum' ];
71 my $edit_link = [ 'javascript:void(0);', sub { ''; } ];
73 my $edit_onclick = sub {
75 my $taxnum = $row->taxnum;
76 include( '/elements/popup_link_onclick.html',
77 'action' => "${p}edit/cust_main_county.html?$taxnum",
78 'actionlabel' => 'Edit tax rate',
80 #default# 'width' => 540,
81 #default# 'color' => '#333399',
89 if ( $ex_oldrow eq $param{'row'} ) {
92 $ex_oldrow = $param{'row'};
95 my $taxnum = $param{'row'}->taxnum;
96 my $url = "${p}edit/cust_main_county-expand.cgi?$taxnum";
99 include( '/elements/popup_link.html',
100 'label' => $param{'label'},
102 'actionlabel' => $param{'desc'},
104 #default# 'width' => 540,
105 #default# 'color' => '#333399',
113 #if ( $ex_oldrow eq $param{'row'} ) {
116 # $ex_oldrow = $param{'row'};
119 my %below = ( 'county' => 'city',
122 my $what = $below{ $param{'col' } };
124 my $taxnum = $param{'row'}->taxnum;
125 my $url = "${p}edit/cust_main_county-add.cgi?taxnum=$taxnum;what=$what";
128 include( '/elements/popup_link.html',
129 'label' => $param{'label'},
131 'actionlabel' => $param{'desc'},
133 #default# 'width' => 540,
134 #default# 'color' => '#333399',
142 my $row = $param{'row'};
143 my $col = $param{'col'};
145 # if $col eq 'state' and $row->city
147 # 'table' => 'cust_main_county',
149 # 'country' => $row->country,
150 # 'state' => $row->state,
151 # 'city' => { op=>'!=', value=>'' },
153 # 'order_by' => 'LIMIT 1',
156 my %below = ( 'county' => 'city',
160 #XXX can still show the link when you have some counties broken down into
161 #cities and others not :/
163 my $taxnum = $param{'row'}->taxnum;
164 my $url = "${p}edit/process/cust_main_county-collapse.cgi?taxnum=$taxnum;".
165 'country='. uri_escape($cgi->param('country')). ';'.
166 'state='. uri_escape($cgi->param('state')). ';'.
167 'county='. uri_escape($cgi->param('county'));
168 $url = "javascript:collapse_areyousure('$url', '$below{$col}', '$col')";
170 qq(<FONT SIZE="-1"><A HREF="$url">$param{'label'}</A></FONT>);
176 my $row = $param{'row'};
177 my $col = $param{'col'};
179 my $taxnum = $param{'row'}->taxnum;
180 my $url = "${p}edit/process/cust_main_county-remove.cgi?taxnum=$taxnum;".
181 'country='. uri_escape($cgi->param('country')). ';'.
182 'state='. uri_escape($cgi->param('state')). ';'.
183 'county='. uri_escape($cgi->param('county'));
184 $url = "javascript:remove_areyousure('$url', '$col')";
186 qq(<FONT SIZE="-1"><A HREF="$url">$param{'label'}</A></FONT>);
190 sub separate_taxclasses_link {
192 my $taxnum = $row->taxnum;
193 my $url = "${p}edit/process/cust_main_county-expand.cgi?taxclass=1;taxnum=$taxnum";
195 qq!<FONT SIZE="-1"><A HREF="$url">!;
198 #un-separate taxclasses too
204 unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
206 #my $conf = new FS::Conf;
207 #my $money_char = $conf->config('money_char') || '$';
208 my $enable_taxclasses = $conf->exists('enable_taxclasses');
212 my $html_init = <<END;
214 function collapse_areyousure(href,col,above) {
215 if (confirm('Are you sure you want to remove all ' + col + ' tax rates for this ' + above + '?') == true)
216 window.location.href = href;
218 function remove_areyousure(href,col) {
219 if (confirm('Are you sure you want to remove this ' + col + '?') == true)
220 window.location.href = href;
225 $html_init .= "<BR>Click on <u>separate taxclasses</u> to specify taxes per taxclass."
226 if $enable_taxclasses;
227 $html_init .= '<BR><BR>';
229 $html_init .= include('/elements/init_overlib.html');
234 if ( $cgi->param('country') =~ /^(\w\w)$/ ) {
238 $cgi->delete('country');
241 if ( $country && $cgi->param('state') =~ /^([\w \-\'\[\]]+)$/ ) {
243 $title = "$state, $title";
245 $cgi->delete('state');
248 if ( $country && $state &&
249 $cgi->param('county') =~
250 /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]+)$/
254 if ( $county eq '__NONE__' ) {
255 $title = "No county, $title";
257 $title = "$county county, $title";
260 $cgi->delete('county');
262 $title = " for $title" if $title;
265 if ( $cgi->param('taxclass') =~ /^([\w \-]+)$/ ) {
267 $title .= " for $taxclass tax class";
269 $cgi->delete('taxclass');
271 if ( $country || $taxclass ) {
272 push @menubar, 'View all tax rates' => $p.'browse/cust_main_county.cgi';
275 $cgi->param('dummy', 1);
278 "window.location = '". $cgi->self_url.
279 ";country=' + encodeURIComponent( document.getElementById('country').options[document.getElementById('country').selectedIndex].value ) + ".
280 "';state=' + encodeURIComponent( document.getElementById('state').options[document.getElementById('state').selectedIndex].value ) +".
281 "';county=' + encodeURIComponent( document.getElementById('county').options[document.getElementById('county').selectedIndex].value );";
283 #restore this so pagination works
284 $cgi->param('country', $country) if $country;
285 $cgi->param('state', $state ) if $state;
286 $cgi->param('county', $county ) if $county;
287 $cgi->param('taxclass', $county ) if $taxclass;
290 '<BR>( show country: '.
291 include('/elements/select-country.html',
292 'country' => $country,
293 'onchange' => $filter_change,
294 'empty_label' => '(all)',
295 'disable_empty' => 0,
296 'disable_stateupdate' => 1,
299 my %states_hash = $country ? states_hash($country) : ();
300 if ( scalar(keys(%states_hash)) > 1 ) {
303 include('/elements/select-state.html',
304 'country' => $country,
306 'onchange' => $filter_change,
307 'empty_label' => '(all)',
308 'disable_empty' => 0,
309 'disable_countyupdate' => 1,
313 '<SELECT NAME="state" ID="state" STYLE="display:none">'.
314 ' <OPTION VALUE="" SELECTED>'.
318 my @counties = ( $country && $state ) ? counties($state, $country) : ();
319 if ( scalar(@counties) > 1 ) {
322 include('/elements/select-county.html',
323 'country' => $country,
326 'onchange' => $filter_change,
327 'empty_label' => '(all)',
328 'empty_data_label' => '(none)',
329 'empty_data_value' => '__NONE__',
330 'disable_empty' => 0,
331 'disable_cityupdate' => 1,
335 '<SELECT NAME="county" ID="county" STYLE="display:none">'.
336 ' <OPTION VALUE="" SELECTED>'.
340 $html_posttotal .= ' )';
342 my $bulk_popup_link =
343 include( '/elements/popup_link_onclick.html',
344 'action' => "${p}edit/bulk-cust_main_county.html?taxnum=MAGIC_taxnum_MAGIC",
345 'actionlabel' => 'Bulk add new tax',
348 #default# 'width' => 540,
349 #default# 'color' => '#333399',
352 my $html_foot = <<END;
353 <SCRIPT TYPE="text/javascript">
355 function setAll(setTo) {
356 theForm = document.taxesForm;
357 for (i=0,n=theForm.elements.length;i<n;i++) {
358 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
359 theForm.elements[i].checked = setTo;
364 function toggleAll() {
365 theForm = document.taxesForm;
366 for (i=0,n=theForm.elements.length;i<n;i++) {
367 if (theForm.elements[i].name.indexOf("cust_main_county") != -1) {
368 if ( theForm.elements[i].checked == true ) {
369 theForm.elements[i].checked = false;
371 theForm.elements[i].checked = true;
377 function bulkPopup(action) {
378 var bulk_popup_link = "$bulk_popup_link";
380 theForm = document.taxesForm;
381 for (i=0,n=theForm.elements.length;i<n;i++) {
382 if ( theForm.elements[i].name.indexOf("cust_main_county") != -1
383 && theForm.elements[i].checked == true
385 var name = theForm.elements[i].name;
386 var taxnum = name.replace(/cust_main_county/, '');
387 if ( bulkstring != '' ) {
388 bulkstring = bulkstring + ',';
390 bulkstring = bulkstring + taxnum;
394 bulkstring = bulkstring + ';action=' + action;
395 if ( bulk_popup_link.length > 1920 ) { // IE 2083 URL limit
396 alert('Too many selections'); // should do some session thing...
399 bulk_popup_link = bulk_popup_link.replace(/MAGIC_taxnum_MAGIC/, bulkstring);
400 eval(bulk_popup_link);
406 <A HREF="javascript:setAll(true)">select all</A> |
407 <A HREF="javascript:setAll(false)">unselect all</A> |
408 <A HREF="javascript:toggleAll()">toggle all</A>
410 <A HREF="javascript:void(0);" onClick="bulkPopup('add');">Add new tax to selected</A>
412 <A HREF="javascript:void(0);" onClick="bulkPopup('edit');">Bulk edit selected</A>
417 my $count_query = 'SELECT COUNT(*) FROM cust_main_county';
419 $hashref->{'country'} = $country;
420 $count_query .= ' WHERE country = '. dbh->quote($country);
423 $hashref->{'state'} = $state;
424 $count_query .= ' AND state = '. dbh->quote($state);
427 if ( $county eq '__NONE__' ) {
428 $hashref->{'county'} = '';
429 $count_query .= " AND ( county = '' OR county IS NULL ) ";
431 $hashref->{'county'} = $county;
432 $count_query .= ' AND county = '. dbh->quote($county);
436 $hashref->{'taxclass'} = $taxclass;
437 $count_query .= ( $count_query =~ /WHERE/i ? ' AND ' : ' WHERE ' ).
438 ' taxclass = '. dbh->quote($taxclass);
444 my @header = ( 'Country', 'State/Province', 'County', 'City' );
445 my @header2 = ( '', '', '', '', );
446 my @links = ( '', '', '', '', );
447 my @link_onclicks = ( '', '', '', '', );
450 my %seen_country = ();
452 my %seen_county = ();
455 sub { my $country = shift->country;
456 return '' if $seen_country{$country}++;
457 code2country($country). " ($country)";
460 sub { my $label = $seen_state{$_[0]->country}->{$_[0]->state}++
461 ? '' : state_label($_[0]->state, $_[0]->country);
463 my $countylinks = ( $_[0]->county && $label )
464 ? ' '. add_link(
465 desc => 'Add more counties',
467 label=> 'add more counties',
473 label=> 'remove all counties',
482 : ' '. expand_link( desc => 'Add States',
484 label => 'add states',
489 $label.$countylinks.$addlink;
493 $seen_county{$_[0]->country}->{$_[0]->state}->{$_[0]->county}++
494 ? '' : $_[0]->county;
498 $citylinks = $_[0]->city
499 ? ' '. add_link(
500 desc => 'Add more cities',
502 label=> 'add more cities',
508 label=> 'remove all cities',
512 : ' '. remove_link( col => 'county',
513 label=> 'remove county',
522 expand_link( desc => 'Add Counties',
524 label => 'add counties',
530 ? $_[0]->city. ' '.
531 remove_link( col => 'city',
532 label=> 'remove city',
537 expand_link( desc => 'Add Cities',
539 label => 'add cities',
547 sub { shift->state ? '000000' : '999999' },
548 sub { shift->county ? '000000' : '999999' },
549 sub { shift->city ? '000000' : '999999' },
552 if ( $conf->exists('enable_taxclasses') ) {
553 push @header, qq!Tax class (<A HREF="${p}edit/part_pkg_taxclass.html">add new</A>)!;
554 push @header2, '(per-package classification)';
555 push @fields, sub { $_[0]->taxclass || '(all) '.
556 separate_taxclasses_link($_[0], 'Separate Taxclasses').
557 'separate taxclasses</A></FONT>'
559 push @color, sub { shift->taxclass ? '000000' : '999999' };
561 push @link_onclicks, '';
574 '(printed on invoices)',
582 my $cust_main_county = shift;
585 if ( $cb_oldrow->city ne $cust_main_county->city
586 || $cb_oldrow->county ne $cust_main_county->county
587 || $cb_oldrow->state ne $cust_main_county->state
588 || $cb_oldrow->country ne $cust_main_county->country
589 || $cb_oldrow->taxclass ne $cust_main_county->taxclass )
599 $cb_oldrow = $cust_main_county;
602 my $taxnum = $cust_main_county->taxnum;
603 qq!<INPUT NAME="cust_main_county$taxnum" TYPE="checkbox" VALUE="1">!;
611 sub { shift->taxname || 'Tax' },
612 sub { shift->tax. '% <FONT SIZE="-1">(edit)</FONT>' },
618 sub { shift->taxname ? '000000' : '666666' },
619 sub { shift->tax ? '000000' : '666666' },
625 my @cell_style = map $cell_style_sub, (1..scalar(@header));
627 push @links, '', '', $edit_link, '';
628 push @link_onclicks, '', '', $edit_onclick, '';