From: ivan Date: Sun, 28 Dec 2008 18:48:16 +0000 (+0000) Subject: fix browse results for selecting counties (resulting from separating tax classes... X-Git-Tag: freeside_1_7_4rc1~129 X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=e8783189b8e95a013e7f56c750083832e6c2a198;p=freeside.git 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 22cc10b8d..02a5480cf 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 fdc518e54..d01067f6a 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 ) %> @@ -98,13 +98,18 @@ <% $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) { +% } 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 4f1c056b5..000000000 --- a/httemplate/edit/cust_main/select-state.html +++ /dev/null @@ -1,24 +0,0 @@ - - -<%init> -my %opt = @_; -foreach my $opt (qw( county state country prefix onchange disabled empty )) { - $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_}); -} - -tie my %states, 'Tie::IxHash', states_hash( $opt{'country'} ); - - 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-state.html b/httemplate/elements/select-state.html new file mode 100644 index 000000000..f7ac2c7bf --- /dev/null +++ b/httemplate/elements/select-state.html @@ -0,0 +1,57 @@ +<%doc> + +Example: + + include( '/elements/select-state.html', + #recommended + country => $current_country, + state => $current_state, + + #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_countyupdate => 0, #bool - disabled update of the select-state.html + ); + + + + + +<%init> + +my %opt = @_; +foreach my $opt (qw( state country prefix onchange disabled empty_label )) { + $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_countyupdate'} ? '' : $pre.'state_changed(this); ' ). + $opt{'onchange'}; + +tie my %states, 'Tie::IxHash', states_hash( $opt{'country'} ); + + + diff --git a/httemplate/misc/payment.cgi b/httemplate/misc/payment.cgi index 9aaa45904..004700488 100644 --- a/httemplate/misc/payment.cgi +++ b/httemplate/misc/payment.cgi @@ -19,165 +19,190 @@ + % if ( $payby eq 'CARD' ) { -% my( $payinfo, $paycvv, $month, $year ) = ( '', '', '', '' ); -% my $payname = $cust_main->first. ' '. $cust_main->getfield('last'); -% my $address1 = $cust_main->address1; -% my $address2 = $cust_main->address2; -% my $city = $cust_main->city; -% my $state = $cust_main->state; -% my $zip = $cust_main->zip; -% if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) { -% $payinfo = $cust_main->paymask; -% $paycvv = $cust_main->paycvv; -% ( $month, $year ) = $cust_main->paydate_monthyear; -% $payname = $cust_main->payname if $cust_main->payname; -% } % - - - Card number - - - - - - + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + + + + + +
- Exp. -
Card number + + + + + - - + + - -
+ Exp. + - / - + / + -
-
CVV2 - (help) -
Exact name on card
Card billing address - -
Address line 2 - -
City - - - - - + +
- - State - +
+
CVV2 + (help) +
Exact name on card
Card billing address + +
Address line 2 + +
City + + + + + - - - -
+ + State + - Zip - -
-
Zip + +
+ + + % } elsif ( $payby eq 'CHEK' ) { -% my( $payinfo1, $payinfo2, $payname, $ss, $paytype, $paystate, -% $stateid, $stateid_state ) -% = ( '', '', '', '', '', '', '', '' ); -% if ( $cust_main->payby =~ /^(CHEK|DCHK)$/ ) { -% $cust_main->paymask =~ /^([\dx]+)\@([\dx]+)$/i -% or die "unparsable payinfo ". $cust_main->payinfo; -% ($payinfo1, $payinfo2) = ($1, $2); -% $payname = $cust_main->payname; -% $ss = $cust_main->ss; -% $paytype = $cust_main->getfield('paytype'); -% $paystate = $cust_main->getfield('paystate'); -% $stateid = $cust_main->getfield('stateid'); -% $stateid_state = $cust_main->getfield('stateid_state'); -% } % - - - - - Account number - - Type - - - - ABA/Routing number - - - (help) - - - - Bank name - - - - Bank state - <% include('../edit/cust_main/select-state.html', #meh - 'empty' => '(choose)', - 'state' => $paystate, - 'country' => $cust_main->country, - 'prefix' => 'pay', - ) %> - - - - Account holder
- Social security or tax ID # - - - - - - Account holder
- Driver’s license or state ID # - - - State - <% include('../edit/cust_main/select-state.html', #meh - 'empty' => '(choose)', - 'state' => $stateid_state, - 'country' => $cust_main->country, - 'prefix' => 'stateid_', - ) %> - -% } +% my( $payinfo1, $payinfo2, $payname, $ss, $paytype, $paystate, +% $stateid, $stateid_state ) +% = ( '', '', '', '', '', '', '', '' ); +% if ( $cust_main->payby =~ /^(CHEK|DCHK)$/ ) { +% $cust_main->paymask =~ /^([\dx]+)\@([\dx]+)$/i +% or die "unparsable payinfo ". $cust_main->payinfo; +% ($payinfo1, $payinfo2) = ($1, $2); +% $payname = $cust_main->payname; +% $ss = $cust_main->ss; +% $paytype = $cust_main->getfield('paytype'); +% $paystate = $cust_main->getfield('paystate'); +% $stateid = $cust_main->getfield('stateid'); +% $stateid_state = $cust_main->getfield('stateid_state'); +% } + + + + + Account number + + Type + + + + ABA/Routing number + + + (help) + + + + Bank name + + + +% if ( $conf->exists('show_bankstate') ) { + + Bank state + <% include('/elements/select-state.html', + 'disable_empty' => 0, + 'empty_label' => '(choose)', + 'state' => $paystate, + 'country' => $cust_main->country, + 'prefix' => 'pay', + ) + %> + + +% } else { + +% } + +% if ( $conf->exists('show_ss') ) { + + + Account holder
+ Social security or tax ID # + + + +% } else { + +% } + +% if ( $conf->exists('show_stateid') ) { + + + Account holder
+ Driver’s license or state ID # + + + State + <% include('/elements/select-state.html', + 'disable_empty' => 0, + 'empty_label' => '(choose)', + 'state' => $stateid_state, + 'country' => $cust_main->country, + 'prefix' => 'stateid_', + ) + %> + + +% } else { + + +% } + +% } #end CARD/CHEK-specific section