X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Ftax_rate_location.pm;h=1a6c47dcf9b252c86f6c9f4dc5f91b7ca3ed5901;hb=72deba42ac5847c2a6bdeea20157035b8f9df7ae;hp=0e0dafebbdb7194610a1eea82aeaffacb5fcadcf;hpb=b3f5d82f666ad38799cae84f0b50bad2b0450d40;p=freeside.git diff --git a/FS/FS/tax_rate_location.pm b/FS/FS/tax_rate_location.pm index 0e0dafebb..1a6c47dcf 100644 --- a/FS/FS/tax_rate_location.pm +++ b/FS/FS/tax_rate_location.pm @@ -125,11 +125,18 @@ sub check { ; return $error if $error; - my $t = qsearchs( 'tax_rate_location', - { map { $_ => $self->$_ } qw( data_vendor geocode ) }, - ); - - return "geocode already in use for this vendor" + my $t; + $t = qsearchs( 'tax_rate_location', + { disabled => '', + ( map { $_ => $self->$_ } qw( data_vendor geocode ) ), + }, + ) + unless $self->disabled; + + $t = $self->by_key( $self->taxratelocationnum ) + if ( !$t && $self->taxratelocationnum ); + + return "geocode ". $self->geocode. " already in use for this vendor" if ( $t && $t->taxratelocationnum != $self->taxratelocationnum ); return "may only be disabled" @@ -144,6 +151,37 @@ sub check { =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 + ); + +} + +=back + =head1 SUBROUTINES =over 4 @@ -194,7 +232,7 @@ sub batch_import { if (exists($hash->{'actionflag'}) && $hash->{'actionflag'} eq 'D') { delete($hash->{actionflag}); - $hash->{deleted} = ''; + $hash->{disabled} = ''; my $tax_rate_location = qsearchs('tax_rate_location', $hash); return "Can't find tax_rate_location to delete: ". join(" ", map { "$_ => ". $hash->{$_} } @fields) @@ -279,7 +317,7 @@ sub batch_import { if ( $error ) { $dbh->rollback if $oldAutoCommit; - return "can't insert tax_rate for $line: $error"; + return "can't insert tax_rate_location for $line: $error"; } }