1 package FS::realestate_location;
8 use FS::Record qw(qsearchs qsearch);
12 FS::realestate_location - Object representing a realestate_location record
16 use FS::realestate_location;
18 $location = new FS::realestate_location \%values;
19 $location = new FS::realestate_location {
21 location_title => 'Superdome',
22 address1 => '1500 Sugar Bowl Dr',
23 city => 'New Orleans',
28 $error = $location->insert;
29 $error = $new_loc->replace($location);
30 $error = $record->check;
32 $error = $location->add_unit('Box Seat No. 42');
33 @units = $location->units;
37 An FS::realestate_location object represents a location for one or more
38 FS::realestate_unit objects. Expected to contain at least one unit, as only
39 realestate_unit objects are assignable to packages via
40 L<FS::svc_realestate>.
42 FS::realestate_location inherits from FS::Record.
44 The following fields are currently supported:
48 =item realestatelocnum
54 =item address1 (optional)
56 =item address2 (optional)
60 =item state (optional)
72 =item new HASHREF (see L<FS::Record>)
76 sub table {'realestate_location';}
78 =item insert (see L<FS::Record>)
82 FS::realestate_location records should never be deleted, only disabled
87 # Once this record has been associated with a customer in any way, it
88 # should not be deleted. todo perhaps, add a is_deletable function that
89 # checks if the record has ever actually been used, and allows deletion
90 # if it hasn't. (entered in error, etc).
91 croak "FS::realestate_location records should never be deleted";
94 =item replace OLD_RECORD (see L<FS::Record>)
96 =item check (see L<FS::Record>)
100 Returns the associated agent
106 return undef unless $self->agentnum;
107 return exists $self->{agent}
109 : $self->{agent} = qsearchs('agent', {agentnum => $self->agentnum} );
113 =item add_unit UNIT_TITLE
115 Create an associated L<FS::realestate_unit> record
120 my ($self, $unit_title) = @_;
121 croak "add_unit() requires a \$unit_title parameter" unless $unit_title;
124 qsearchs('realestate_unit',{
125 realestatelocnum => $self->realestatelocnum,
126 unit_title => $unit_title,
129 return "Unit Title ($unit_title) has already been used for location (".
130 $self->location_title.")";
133 my $unit = FS::realestate_unit->new({
134 realestatelocnum => $self->realestatelocnum,
135 agentnum => $self->agentnum,
136 unit_title => $unit_title,
138 my $err = $unit->insert;
139 die "Error creating FS::realestate_new record: $err" if $err;
147 Returns all units associated with this location
155 {realestatelocnum => $self->realestatelocnum}
173 L<FS::record>, L<FS::realestate_unit>, L<FS::svc_realestate>