+=item find_or_insert
+
+Finds an existing, non-disabled tax jurisdiction matching the data_vendor
+and geocode fields. If there is one, updates its city, county, state, and
+country to match this record. If there is no existing record, inserts this
+record.
+
+=cut
+
+sub find_or_insert {
+ my $self = shift;
+ my $existing = $self->existing_search;
+ if ($existing) {
+ my $update = 0;
+ foreach (qw(city county state country)) {
+ if ($self->get($_) ne $existing->get($_)) {
+ $update++;
+ }
+ }
+ $self->set(taxratelocationnum => $existing->taxratelocationnum);
+ if ($update) {
+ return $self->replace($existing);
+ } else {
+ return;
+ }
+ } else {
+ return $self->insert;
+ }
+}
+
+sub existing_search {
+ my $self = shift;
+
+ qsearchs( 'tax_rate_location',
+ { disabled => '',
+ map { $_ => $self->$_ } qw( data_vendor geocode )
+ }
+ );
+}
+
+=back
+
+=head1 CLASS METHODS
+
+=item location_sql KEY => VALUE, ...
+
+Returns an SQL fragment identifying matching tax_rate_location /
+cust_bill_pkg_tax_rate_location records.
+
+Parameters are county, state, city and locationtaxid
+
+=cut
+
+sub location_sql {
+ my($class, %param) = @_;
+
+ my %pn = (
+ 'city' => 'tax_rate_location.city',
+ 'county' => 'tax_rate_location.county',
+ 'state' => 'tax_rate_location.state',
+ 'locationtaxid' => 'cust_bill_pkg_tax_rate_location.locationtaxid',
+ );
+
+ my %ph = map { $pn{$_} => dbh->quote($param{$_}) } keys %pn;
+
+ join( ' AND ',
+ map { "( $_ = $ph{$_} OR $ph{$_} = '' AND $_ IS NULL)" } keys %ph
+ );
+
+}
+