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 {
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;
34 @units = $location->active_units;
38 An FS::realestate_location object represents a location for one or more
39 FS::realestate_unit objects. Expected to contain at least one unit, as only
40 realestate_unit objects are assignable to packages via
41 L<FS::svc_realestate>.
43 FS::realestate_location inherits from FS::Record.
45 The following fields are currently supported:
49 =item realestatelocnum
55 =item address1 (optional)
57 =item address2 (optional)
61 =item state (optional)
73 =item new HASHREF (see L<FS::Record>)
77 sub table {'realestate_location';}
79 =item insert (see L<FS::Record>)
83 FS::realestate_location records should never be deleted, only disabled
88 # Once this record has been associated with a customer in any way, it
89 # should not be deleted. todo perhaps, add a is_deletable function that
90 # checks if the record has ever actually been used, and allows deletion
91 # if it hasn't. (entered in error, etc).
92 croak "FS::realestate_location records should never be deleted";
95 =item replace OLD_RECORD (see L<FS::Record>)
97 =item check (see L<FS::Record>)
101 Returns the associated agent
107 return undef unless $self->agentnum;
108 return exists $self->{agent}
110 : $self->{agent} = qsearchs('agent', {agentnum => $self->agentnum} );
114 =item add_unit UNIT_TITLE
116 Create an associated L<FS::realestate_unit> record
121 my ($self, $unit_title) = @_;
122 croak "add_unit() requires a \$unit_title parameter" unless $unit_title;
125 qsearchs('realestate_unit',{
126 realestatelocnum => $self->realestatelocnum,
127 unit_title => $unit_title,
130 return "Unit Title ($unit_title) has already been used for location (".
131 $self->location_title.")";
134 my $unit = FS::realestate_unit->new({
135 realestatelocnum => $self->realestatelocnum,
136 agentnum => $self->agentnum,
137 unit_title => $unit_title,
139 my $err = $unit->insert;
140 die "Error creating FS::realestate_new record: $err" if $err;
148 Returns all units associated with this location
156 {realestatelocnum => $self->realestatelocnum}
174 L<FS::record>, L<FS::realestate_unit>, L<FS::svc_realestate>