1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
package FS::realestate_unit;
use strict;
use warnings;
use Carp qw(croak);
use base 'FS::Record';
use FS::Record qw(qsearch qsearchs);
=head1 NAME
FS::realestate_unit - Object representing a realestate_unit record
=head1 SYNOPSIS
use FS::realestate_unit;
$record = new FS:realestate_unit \%values;
$record = new FS::realestate_unit {
realestatelocnum => 42,
agentnum => 1,
unit_title => 'Ste 404',
};
$error = $record->insert;
$error = $new_rec->replace($record)
$error = $record->check;
$location = $record->location;
=head1 DESCRIPTION
An FS::realestate_unit object represents an invoicable unit of real estate.
Object may represent a single property, such as a rental house. It may also
represent a group of properties sharing a common address or identifier, such
as a shopping mall, apartment complex, or office building, concert hall.
A FS::realestate_unit object must be associated with a FS::realestate_location
FS::realestate_unit inherits from FS::Record.
The following fields are currently supported:
=over 4
=item realestatenum
=item realestatelocnum
=item agentnum
=item unit_title
=item disabled
=back
=head1 METHODS
=over 4
=item new HASHREF (see L<FS::Record>)
=cut
sub table {'realestate_unit';}
=item insert (see L<FS::Record>)
=item delete
FS::realestate_unit records should never be deleted, only disabled
=cut
sub delete {
# Once this record has been associated with a customer in any way, it
# should not be deleted. todo perhaps, add a is_deletable function that
# checks if the record has ever actually been used, and allows deletion
# if it hasn't. (entered in error, etc).
croak "FS::realestate_unit records should never be deleted";
}
=item replace OLD_RECORD (see L<FS::Record>)
=item check (see L<FS::Record>)
=item agent
Returns the associated agent, if any, for this object
=cut
sub agent {
my $self = shift;
return undef unless $self->agentnum;
return qsearchs('agent', {agentnum => $self->agentnum} );
}
=item location
Return the associated FS::realestate_location object
=cut
sub location {
my $self = shift;
return $self->{location} if exists $self->{location};
return $self->{location} = qsearchs(
'realestate_location',
{realestatelocnum => $self->realestatelocnum}
);
}
=back
=item custnum
Pull the assigned custnum for this unit, if provisioned
=cut
sub custnum {
my $self = shift;
return $self->{custnum}
if $self->{custnum};
# select cust_pkg.custnum
# from svc_realestate
# LEFT JOIN cust_svc ON svc_realestate.svcnum = cust_svc.svcnum
# LEFT JOIN cust_pkg ON cust_svc.pkgnum = cust_pkg.pkgnum
# WHERE svc_realestate.realestatenum = $realestatenum
my $row = qsearchs({
select => 'cust_pkg.custnum',
table => 'svc_realestate',
addl_from => 'LEFT JOIN cust_svc ON svc_realestate.svcnum = cust_svc.svcnum '
. 'LEFT JOIN cust_pkg ON cust_svc.pkgnum = cust_pkg.pkgnum ',
extra_sql => 'WHERE svc_realestate.realestatenum = '.$self->realestatenum,
});
return
unless $row && $row->custnum;
return $self->{custnum} = $row->custnum;
}
=head1 SUBROUTINES
=over 4
=cut
=back
=head1 SEE ALSO
L<FS::record>, L<FS::realestate_location>, L<FS::svc_realestate>
=cut
1;
|