From: ivan Date: Sun, 28 Dec 2008 18:48:51 +0000 (+0000) Subject: fix browse results for selecting counties (resulting from separating tax classes... X-Git-Tag: root_of_webpay_support~174 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=d8cb6cd67cc574c90dbbfbd8db2da6711c516d65 fix browse results for selecting counties (resulting from separating tax classes), also add dropdowns to browse by state and county, RT#4496 --- diff --git a/httemplate/browse/cust_main_county.cgi b/httemplate/browse/cust_main_county.cgi index 1e969aa8f..c4d1d1882 100755 --- a/httemplate/browse/cust_main_county.cgi +++ b/httemplate/browse/cust_main_county.cgi @@ -32,18 +32,6 @@ 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; @@ -153,16 +141,20 @@ 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 +173,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=' + document.getElementById('country').options[document.getElementById('country').selectedIndex].value + ". + "';state=' + document.getElementById('state').options[document.getElementById('state').selectedIndex].value +". + "';county=' + document.getElementById('county').options[document.getElementById('county').selectedIndex].value;"; #restore this so pagination works $cgi->param('country', $country) if $country; @@ -192,15 +186,57 @@ $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', @@ -281,11 +317,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; diff --git a/httemplate/edit/cust_main/billing.html b/httemplate/edit/cust_main/billing.html index d4c503412..8724db9dc 100644 --- a/httemplate/edit/cust_main/billing.html +++ b/httemplate/edit/cust_main/billing.html @@ -199,11 +199,11 @@ % ( $conf->exists('show_bankstate') ? % qq!$paystate_label!. % qq!!. -% include('select-state.html', +% include('/elements/select-state.html', % 'empty' => '(choose)', % 'state' => $cust_main->paystate, % 'country' => $cust_main->country, -% 'prefix' => 'pay', +% 'prefix' => 'pay', % ). "" % : '' diff --git a/httemplate/edit/cust_main/contact.html b/httemplate/edit/cust_main/contact.html index 2d37dc895..d93d41728 100644 --- a/httemplate/edit/cust_main/contact.html +++ b/httemplate/edit/cust_main/contact.html @@ -54,11 +54,11 @@ ><%$r%>County - <% include('select-county.html', %select_hash ) %> + <% include('/elements/select-county.html', %select_hash ) %> <%$r%>State - <% include('select-state.html', %select_hash ) %> + <% include('/elements/select-state.html', %select_hash ) %> <%$r%>Zip @@ -68,7 +68,7 @@ <%$r%>Country - <% include('select-country.html', %select_hash ) %> + <% include('/elements/select-country.html', %select_hash ) %> % if ( !$pre ) { % } @@ -102,11 +102,15 @@ <% $stateid_label %> > <% $stateid_state_label %> - <% include('select-state.html', 'state' => $cust_main->stateid_state, - 'country' => $cust_main->country, - 'prefix' => 'stateid_', - 'onchange' => $onchange, - 'disabled' => $disabled) %> + <% include('/elements/select-state.html', + 'state' => $cust_main->stateid_state, + 'country' => $cust_main->country, + 'prefix' => 'stateid_', + 'onchange' => $onchange, + 'disabled' => $disabled, + ) + %> + % } elsif ( !$pre ) { diff --git a/httemplate/edit/cust_main/select-country.html b/httemplate/edit/cust_main/select-country.html deleted file mode 100644 index 137f61975..000000000 --- a/httemplate/edit/cust_main/select-country.html +++ /dev/null @@ -1,76 +0,0 @@ - -<% include('/elements/xmlhttp.html', - 'url' => $p.'misc/states.cgi', - 'subs' => [ $opt{'prefix'}. 'get_states' ], - ) -%> - - - - - -<%init> -my %opt = @_; -foreach my $opt (qw( county state country prefix onchange disabled )) { - $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_}); -} - -my $conf = new FS::Conf; -my $countrydefault = $conf->config('countrydefault') || 'US'; - - diff --git a/httemplate/edit/cust_main/select-county.html b/httemplate/edit/cust_main/select-county.html deleted file mode 100644 index 0dc826896..000000000 --- a/httemplate/edit/cust_main/select-county.html +++ /dev/null @@ -1,113 +0,0 @@ -% if ( $countyflag ) { - - <% include('/elements/xmlhttp.html', - 'url' => $p.'misc/counties.cgi', - 'subs' => [ $opt{'prefix'}. 'get_counties' ], - ) - %> - - - - - -% } else { - - - - - - -% } - -<%init> - -my %opt = @_; -foreach my $opt (qw( county state country prefix onchange disabled )) { - $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_}); -} - -my @counties = (); -if ( $countyflag ) { - - @counties = counties( $opt{'state'}, $opt{'country'} ); - - # this is very hacky - unless ( scalar(@counties) > 1 ) { - if ( $opt{'disabled'} =~ /STYLE=/i ) { - $opt{'disabled'} =~ s/STYLE="([^"]+)"/STYLE="$1; display:none"/i; - } else { - $opt{'disabled'} .= ' STYLE="display:none"'; - } - } - -} - - -<%once> - -my $sql = "SELECT COUNT(*) FROM cust_main_county". - " WHERE county IS NOT NULL AND county != ''"; -my $sth = dbh->prepare($sql) or die dbh->errstr; -$sth->execute or die $sth->errstr; -my $countyflag = $sth->fetchrow_arrayref->[0]; - - diff --git a/httemplate/edit/cust_main/select-state.html b/httemplate/edit/cust_main/select-state.html deleted file mode 100644 index ce08443e4..000000000 --- a/httemplate/edit/cust_main/select-state.html +++ /dev/null @@ -1,4 +0,0 @@ -<% include('/elements/select-state.html', @_) %> -<%init> -warn "cust_main/select-state.html depreated; use /elements/select-state.html instead"; - diff --git a/httemplate/elements/select-country.html b/httemplate/elements/select-country.html new file mode 100644 index 000000000..c4368c271 --- /dev/null +++ b/httemplate/elements/select-country.html @@ -0,0 +1,120 @@ +<%doc> + +Example: + + include( '/elements/select-country.html', + #recommended + country => $current_country, + + #optional + prefix => $optional_unique_prefix, + onchange => $javascript, + disabled => 0, #bool + disable_empty => 1, #defaults to 1, disable the empty option + empty_label => 'all', #label for empty option + disable_stateupdate => 0, #bool - disabled update of the select-state.html + + ); + + +% unless ( $opt{'disable_stateupdate'} ) { + + <% include('/elements/xmlhttp.html', + 'url' => $p.'misc/states.cgi', + 'subs' => [ $pre. 'get_states' ], + ) + %> + + + +% } + + + +<%init> + +my %opt = @_; +foreach my $opt (qw( country prefix onchange disabled disable_stateupdate )) { + $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt}); +} + +$opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'}); + +my $pre = $opt{'prefix'}; + +my $onchange = + ( $opt{'disable_stateupdate'} ? '' : $pre.'country_changed(this); ' ). + $opt{'onchange'}; + +my $conf = new FS::Conf; +my $default = $conf->config('countrydefault') || 'US'; + +my @all_countries = ( + sort { ($b eq $default) <=> ($a eq $default) + or code2country($a) cmp code2country($b) + } + map { $_->country } + qsearch({ + 'select' => 'country', + 'table' => 'cust_main_county', + 'hashref' => {}, + 'extra_sql' => 'GROUP BY country', + }) + ); + + diff --git a/httemplate/elements/select-county.html b/httemplate/elements/select-county.html new file mode 100644 index 000000000..8ef34dbe6 --- /dev/null +++ b/httemplate/elements/select-county.html @@ -0,0 +1,152 @@ +<%doc> + +Example: + + include( '/elements/select-county.html', + #recommended + country => $current_country, + state => $current_state, + county => $current_county, + + #optional + prefix => $optional_unique_prefix, + onchange => $javascript, + disabled => 0, #bool + disable_empty => 1, #defaults to 1, disable the empty option + empty_label => 'all', #label for empty option + ); + + +% if ( $countyflag ) { + + <% include('/elements/xmlhttp.html', + 'url' => $p.'misc/counties.cgi', + 'subs' => [ $pre. 'get_counties' ], + ) + %> + + + + + +% } else { + + + + + +% } + +<%init> + +my %opt = @_; +foreach my $opt (qw( county state country prefix onchange disabled + empty_value )) { + $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt}); +} + +$opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'}); + +my $pre = $opt{'prefix'}; + +my @counties = (); +if ( $countyflag ) { + + @counties = map { length($_) ? $_ : $opt{'empty_data_value'} } + counties( $opt{'state'}, $opt{'country'} ); + + # this is very hacky + unless ( scalar(@counties) > 1 ) { + if ( $opt{'disabled'} =~ /STYLE=/i ) { + $opt{'disabled'} =~ s/STYLE="([^"]+)"/STYLE="$1; display:none"/i; + } else { + $opt{'disabled'} .= ' STYLE="display:none"'; + } + } + +} + + +<%once> + +my $sql = "SELECT COUNT(*) FROM cust_main_county". + " WHERE county IS NOT NULL AND county != ''"; +my $sth = dbh->prepare($sql) or die dbh->errstr; +$sth->execute or die $sth->errstr; +my $countyflag = $sth->fetchrow_arrayref->[0]; + + diff --git a/httemplate/elements/select-did.html b/httemplate/elements/select-did.html index a8ef09d61..069516476 100644 --- a/httemplate/elements/select-did.html +++ b/httemplate/elements/select-did.html @@ -18,8 +18,9 @@ Example: <% include('/elements/select-state.html', - 'country' => $country, - 'empty' => 'Select state', + 'country' => $country, + 'disable_empty' => 0, + 'empty_label' => 'Select state', ) %> diff --git a/httemplate/elements/select-state.html b/httemplate/elements/select-state.html index 4f1c056b5..f7ac2c7bf 100644 --- a/httemplate/elements/select-state.html +++ b/httemplate/elements/select-state.html @@ -1,12 +1,35 @@ - + +% unless ( $opt{'disable_empty'} ) { +