rt# 74031 work in progress
[freeside.git] / FS / FS / realestate_property.pm
1 package FS::realestate_property;
2 use strict;
3 use warnings;
4 use Carp qw(croak);
5
6 use base 'FS::Record';
7 use FS::Record qw(qsearch qsearchs);
8
9 =head1 NAME
10
11 FS::realestate_property - Object representing a realestate_property record
12
13 =head1 SYNOPSIS
14
15   use FS::realestate_property;
16
17   $record = new FS:realestate_property  \%values;
18   $record = new FS::realestate_property {
19     title    => 'Superdome',
20     address1 => '1500 Sugar Bowl Dr',
21     city     => 'New Orleans',
22     state    => 'LA',
23     zip      => '70112',
24     disabled => 0,
25     agentnum => 1,
26   };
27
28   $error = $record->insert;
29   $error = $new_rec->replace($record)
30   $error = $record->check;
31
32   $sub_record = $record->add_subproperty('Box Seat No. 42');
33
34   @subprops = $record->subproperties;
35   @subprops = $record->enabled_subproperties;
36
37 =head1 DESCRIPTION
38
39 An FS::realestate_property object represents a real estate property.  This
40 object may represent a single property, such as a rental house.  It may also
41 represent a group of properties sharing a common address or identifier, such
42 as a shopping mall, apartment complex, or office building.
43
44 FS::realestate_property inherits from FS::Record.
45
46 The following fields are currently supported:
47
48 =over 4
49
50 =item propnum
51
52 =item agentnum
53
54 =item title
55
56 =item address1 *optional
57
58 =item address2 *optional
59
60 =item city     *optional
61
62 =item state    *optional
63
64 =item zip      *optional
65
66 =item disabled
67
68 =back
69
70 =head1 METHODS
71
72 =over 4
73
74 =item new HASHREF (see L<FS::Record>)
75
76 =cut
77
78 sub table {'realestate_property';}
79
80 =item insert (see L<FS::Record>)
81
82 =item delete
83
84   FS::realestate_property records should never be deleted, only disabled
85
86 =cut
87
88 sub delete {
89   # Once this record has been associated with a customer in any way, it
90   # should not be deleted.  todo perhaps, add a is_deletable function that
91   # checks if the record has ever actually been used, and allows deletion
92   # if it hasn't.  (entered in error, etc).
93   croak "FS::realestate_property records should never be deleted";
94 }
95
96
97 =item replace OLD_RECORD (see L<FS::Record>)
98
99 =item check (see L<FS::Record>)
100
101 =item agent
102
103 Returns the associated agent, if any, for this object
104
105 =cut
106
107 sub agent {
108   my $self = shift;
109   return undef unless $self->agentnum;
110   return qsearchs('agent', {agentnum => $self->agentnum} );
111 }
112
113
114 =item subproperties
115
116 Returns all subproperties linked to this property
117
118 =cut
119
120 sub subproperties {
121   qsearch('realestate_subproperty', {propnum => shift->propnum} );
122 }
123
124
125 =item enabled_subproperties
126
127 Returns all subproperties linked to this property where disabled = 0
128
129 =cut
130
131 sub enabled_subproperties {
132   qsearch( 'realestate_subproperty', {
133     propnum => shift->propnum,
134     disabled => 0,
135   });
136 }
137
138 =item add_subproperty SUBPROPERTY_TITLE
139
140 Create a new subproperty record for this property
141
142 =cut
143
144 sub add_subproperty {
145   my ($self, $subtitle) = @_;
146   croak "add_subproperty() requires a \$subtitle parameter" unless $subtitle;
147
148   my $subp = new FS::realestate_subproperty {
149     propnum  => $self->propnum,
150     subtitle => $subtitle,
151     disabled => 0,
152   };
153   my $err = $subp->insert;
154   die "Error inserting subproperty: $err" if $err;
155   $subp;
156 }
157
158
159 =back
160
161 =head1 SUBROUTINES
162
163 =over 4
164
165 =cut
166
167
168 =back
169
170 =head1 SEE ALSO
171
172 L<FS::record>, L<FS::realestate_subproperty>, L<FS::svc_realestate>
173
174 =cut
175
176 1;