use vars qw( $import );
use Locale::Country;
use FS::UID qw( dbh driver_name );
-use FS::Record qw( qsearch ); #qsearchs );
+use FS::Record qw( qsearch qsearchs );
use FS::Conf;
use FS::prospect_main;
use FS::cust_main;
sub table { 'cust_location'; }
+=item new_or_existing HASHREF
+
+Returns an existing location matching the customer and address fields in
+HASHREF, if one exists; otherwise returns a new location containing those
+fields. The following fields must match: address1, address2, city, county,
+state, zip, country, geocode, disabled. Other fields are only required
+to match if they're specified in HASHREF.
+
+The new location will not be inserted; the calling code must call C<insert>
+(or a method such as C<move_to>) to insert it, and check for errors at that
+point.
+
+=cut
+
+sub new_or_existing {
+ my $class = shift;
+ my %hash = ref($_[0]) ? %{$_[0]} : @_;
+ foreach ( qw(address1 address2 city county state zip country geocode
+ disabled ) ) {
+ # empty fields match only empty fields
+ $hash{$_} = '' if !defined($hash{$_});
+ }
+ return qsearchs('cust_location', \%hash) || $class->new(\%hash);
+}
+
=item insert
Adds this record to the database. If there is an error, returns the error,
|| $self->ut_coordn('latitude')
|| $self->ut_coordn('longitude')
|| $self->ut_enum('coord_auto', [ '', 'Y' ])
+ || $self->ut_enum('addr_clean', [ '', 'Y' ])
|| $self->ut_alphan('location_type')
|| $self->ut_textn('location_number')
|| $self->ut_enum('location_kind', [ '', 'R', 'B' ] )
return "Unit # is required";
}
- $self->set_coord
- unless $import || ($self->latitude && $self->longitude);
-
# tricky...we have to allow for the customer to not be inserted yet
return "No prospect or customer!" unless $self->prospectnum
|| $self->custnum
my $dbh = dbh;
my $error = '';
+ # prevent this from failing because of pkg_svc quantity limits
+ local( $FS::cust_svc::ignore_quantity ) = 1;
+
if ( !$new->locationnum ) {
$error = $new->insert;
if ( $error ) {
$prefix . $self->SUPER::location_label(%opt);
}
+=item county_state_county
+
+Returns a string consisting of just the county, state and country.
+
+=cut
+
+sub county_state_country {
+ my $self = shift;
+ my $label = $self->country;
+ $label = $self->state.", $label" if $self->state;
+ $label = $self->county." County, $label" if $self->county;
+ $label;
+}
+
=back
=head1 CLASS METHODS