X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fbrowse%2Fcust_main_county.cgi;h=232e6883ca477cdd75fbfac25fdecc467c35ac93;hb=dbf7e7eb594830d3ac3db43039f470bb38489acf;hp=fc10226840743f5d88b37dfdd55d0b7d43527052;hpb=9eded70a59f22d7df3b645ad3636e28e0fd08bee;p=freeside.git diff --git a/httemplate/browse/cust_main_county.cgi b/httemplate/browse/cust_main_county.cgi index fc1022684..232e6883c 100755 --- a/httemplate/browse/cust_main_county.cgi +++ b/httemplate/browse/cust_main_county.cgi @@ -23,27 +23,11 @@ 'link_onclicks' => \@link_onclicks, ) %> -% -% # collapse state -% # % } -% <%once> my $conf = new FS::Conf; my $money_char = $conf->config('money_char') || '$'; -my @manual_countries = ( 'US', 'CA', 'AU', 'NZ', 'GB' ); #some manual ordering -my @all_countries = ( @manual_countries, - grep { my $c = $_; ! grep { $c eq $_ } @manual_countries } - map { $_->country } - qsearch({ - 'select' => 'country', - 'table' => 'cust_main_county', - 'hashref' => {}, - 'extra_sql' => 'GROUP BY country', - }) - ); - my $exempt_sub = sub { my $cust_main_county = shift; @@ -114,6 +98,17 @@ sub expand_link { ''; } +sub collapse_link { + my %param = @_; + + my $taxnum = $param{'row'}->taxnum; + my $url = "${p}edit/process/cust_main_county-collapse.cgi?$taxnum"; + $url = "javascript:collapse_areyousure('$url')"; + + qq($param{'label'}); +} + + sub separate_taxclasses_link { my( $row ) = @_; my $taxnum = $row->taxnum; @@ -122,6 +117,8 @@ sub separate_taxclasses_link { qq!!; } +#un-separate taxclasses too + <%init> @@ -134,9 +131,18 @@ my $enable_taxclasses = $conf->exists('enable_taxclasses'); my @menubar; -my $html_init = - "Click on add states to specify a country's tax rates by state or province. -
Click on add counties to specify a state's tax rates by county."; +my $html_init = < + function collapse_areyousure(href) { + if (confirm("Are you sure you want to remove all county tax rates for this state?") == true) + window.location.href = href; + } + + + Click on add states to specify a country's tax rates by state or province. +
Click on add counties to specify a state's tax rates by county, or remove counties to remove per-county tax rates. +END + $html_init .= "
Click on separate taxclasses to specify taxes per taxclass." if $enable_taxclasses; $html_init .= '

'; @@ -153,16 +159,24 @@ if ( $cgi->param('country') =~ /^(\w\w)$/ ) { $cgi->delete('country'); my $state = ''; -if ( $cgi->param('state') =~ /^([\w \-\'\[\]]+)$/ ) { +if ( $country && $cgi->param('state') =~ /^([\w \-\'\[\]]+)$/ ) { $state = $1; $title = "$state, $title"; } $cgi->delete('state'); my $county = ''; -if ( $cgi->param('county') =~ /^([\w \-\'\[\]]+)$/ ) { +if ( $country && $state && + $cgi->param('county') =~ + /^([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]+)$/ + ) +{ $county = $1; - $title = "$county county, $title"; + if ( $county eq '__NONE__' ) { + $title = "No county, $title"; + } else { + $title = "$county county, $title"; + } } $cgi->delete('county'); @@ -181,9 +195,11 @@ if ( $country || $taxclass ) { $cgi->param('dummy', 1); -my $country_filter_change = - "window.location = '". - $cgi->self_url. ";country=' + this.options[this.selectedIndex].value;"; +my $filter_change = + "window.location = '". $cgi->self_url. + ";country=' + encodeURIComponent( document.getElementById('country').options[document.getElementById('country').selectedIndex].value ) + ". + "';state=' + encodeURIComponent( document.getElementById('state').options[document.getElementById('state').selectedIndex].value ) +". + "';county=' + encodeURIComponent( document.getElementById('county').options[document.getElementById('county').selectedIndex].value );"; #restore this so pagination works $cgi->param('country', $country) if $country; @@ -192,19 +208,61 @@ $cgi->param('county', $county ) if $county; $cgi->param('taxclass', $county ) if $taxclass; my $html_posttotal = - '(show country: '. - qq()'; + '
( show country: '. + include('/elements/select-country.html', + 'country' => $country, + 'onchange' => $filter_change, + 'empty_label' => '(all)', + 'disable_empty' => 0, + 'disable_stateupdate' => 1, + ); + +my %states_hash = $country ? states_hash($country) : (); +if ( scalar(keys(%states_hash)) > 1 ) { + $html_posttotal .= + ' show state: '. + include('/elements/select-state.html', + 'country' => $country, + 'state' => $state, + 'onchange' => $filter_change, + 'empty_label' => '(all)', + 'disable_empty' => 0, + 'disable_countyupdate' => 1, + ); +} else { + $html_posttotal .= + ''; +} + +my @counties = ( $country && $state ) ? counties($state, $country) : (); +if ( scalar(@counties) > 1 ) { + $html_posttotal .= + ' show county: '. + include('/elements/select-county.html', + 'country' => $country, + 'state' => $state, + 'county' => $county, + 'onchange' => $filter_change, + 'empty_label' => '(all)', + 'empty_data_label' => '(none)', + 'empty_data_value' => '__NONE__', + 'disable_empty' => 0, + 'disable_countyupdate' => 1, + ); +} else { + $html_posttotal .= + ''; +} + +$html_posttotal .= ' )'; my $bulk_popup_link = include( '/elements/popup_link_onclick.html', - 'action' => "${p}edit/bulk_cust_main_county.html?MAGIC_taxnum_MAGIC", + 'action' => "${p}edit/bulk-cust_main_county.html?MAGIC_taxnum_MAGIC", 'actionlabel' => 'Bulk add new tax', 'nofalse' => 1, 'height' => 420, @@ -281,11 +339,16 @@ if ( $country ) { } if ( $state ) { $hashref->{'state'} = $state; - $count_query .= ' AND state = '. dbh->quote($state); + $count_query .= ' AND state = '. dbh->quote($state); } if ( $county ) { - $hashref->{'country'} = $country; - $count_query .= ' AND county = '. dbh->quote($county); + if ( $county eq '__NONE__' ) { + $hashref->{'county'} = ''; + $count_query .= " AND ( county = '' OR county IS NULL ) "; + } else { + $hashref->{'county'} = $county; + $count_query .= ' AND county = '. dbh->quote($county); + } } if ( $taxclass ) { $hashref->{'taxclass'} = $taxclass; @@ -315,11 +378,16 @@ my @fields = ( ) ) }, - sub { $_[0]->county || '(all) '. - expand_link( desc => 'Add Counties', - row => $_[0], - label => 'add counties', - ) + sub { $_[0]->county + ? $_[0]->county. ' '. + collapse_link( label=> 'remove counties', + row => $_[0], + ) + : '(all) '. + expand_link( desc => 'Add Counties', + row => $_[0], + label => 'add counties', + ); }, );