1 package FS::realestate_unit;
7 use FS::Record qw(qsearch qsearchs);
11 FS::realestate_unit - Object representing a realestate_unit record
15 use FS::realestate_unit;
17 $record = new FS:realestate_unit \%values;
18 $record = new FS::realestate_unit {
19 realestatelocnum => 42,
21 unit_title => 'Ste 404',
24 $error = $record->insert;
25 $error = $new_rec->replace($record)
26 $error = $record->check;
28 $location = $record->location;
32 An FS::realestate_unit object represents an invoicable unit of real estate.
33 Object may represent a single property, such as a rental house. It may also
34 represent a group of properties sharing a common address or identifier, such
35 as a shopping mall, apartment complex, or office building, concert hall.
37 A FS::realestate_unit object must be associated with a FS::realestate_location
39 FS::realestate_unit inherits from FS::Record.
41 The following fields are currently supported:
47 =item realestatelocnum
61 =item new HASHREF (see L<FS::Record>)
65 sub table {'realestate_unit';}
67 =item insert (see L<FS::Record>)
71 FS::realestate_unit records should never be deleted, only disabled
76 # Once this record has been associated with a customer in any way, it
77 # should not be deleted. todo perhaps, add a is_deletable function that
78 # checks if the record has ever actually been used, and allows deletion
79 # if it hasn't. (entered in error, etc).
80 croak "FS::realestate_unit records should never be deleted";
84 =item replace OLD_RECORD (see L<FS::Record>)
86 =item check (see L<FS::Record>)
90 Returns the associated agent, if any, for this object
96 return undef unless $self->agentnum;
97 return qsearchs('agent', {agentnum => $self->agentnum} );
102 Return the associated FS::realestate_location object
108 return $self->{location} if exists $self->{location};
109 return $self->{location} = qsearchs(
110 'realestate_location',
111 {realestatelocnum => $self->realestatelocnum}
119 Pull the assigned custnum for this unit, if provisioned
125 return $self->{custnum}
128 # select cust_pkg.custnum
129 # from svc_realestate
130 # LEFT JOIN cust_svc ON svc_realestate.svcnum = cust_svc.svcnum
131 # LEFT JOIN cust_pkg ON cust_svc.pkgnum = cust_pkg.pkgnum
132 # WHERE svc_realestate.realestatenum = $realestatenum
135 select => 'cust_pkg.custnum',
136 table => 'svc_realestate',
137 addl_from => 'LEFT JOIN cust_svc ON svc_realestate.svcnum = cust_svc.svcnum '
138 . 'LEFT JOIN cust_pkg ON cust_svc.pkgnum = cust_pkg.pkgnum ',
139 extra_sql => 'WHERE svc_realestate.realestatenum = '.$self->realestatenum,
143 unless $row && $row->custnum;
145 return $self->{custnum} = $row->custnum;
159 L<FS::record>, L<FS::realestate_location>, L<FS::svc_realestate>