rt# 74031 work in progress
[freeside.git] / FS / FS / realestate_subproperty.pm
1 package FS::realestate_subproperty;
2 use strict;
3 use warnings;
4 use Carp qw(croak);
5
6 use base 'FS::Record';
7
8 use FS::Record qw(qsearchs);
9
10 =head1 NAME
11
12 FS::realestate_subproperty - Object representing a realestate_subproperty record
13
14 =head1 SYNOPSIS
15
16   use FS::realestate_subproperty;
17
18   $record = new FS::realestate_subproperty \%values;
19   $record = new FS::realestate_subproperty {
20     propnum => 65535,
21     subtitle => 'Box Seat No. 42',
22   };
23
24   $error = $record->insert;
25   $error = new_rec->replace($record);
26   $error = $record->check;
27
28   $parent = $record->property;
29
30 =head1 DESCRIPTION
31
32 An FS::realestate_subproperty object represents a unit of real estate property.
33 Every L<FS::realestate_property> must contain at least one subproperty, or unit,
34 which is the actual unit considered for sale, rent, etc as tied to
35 L<FS::svc_realestate>.
36
37 FS::realestate_subproperty inherits from FS::Record.
38
39 The following fields are currently supported:
40
41 =over 4
42
43 =item subpropnum
44
45 =item propnum
46
47 =item subtitle
48
49 =item disabled
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF (see L<FS::Record>)
58
59 =cut
60
61 sub table {'realestate_subproperty';}
62
63 =item insert (see L<FS::Record>)
64
65 =item delete
66
67   FS::realestate_subproperty records should never be deleted, only disabled
68
69 =cut
70
71 sub delete {
72   # Once this record has been associated with a customer in any way, it
73   # should not be deleted.  todo perhaps, add a is_deletable function that
74   # checks if the record has ever actually been used, and allows deletion
75   # if it hasn't.  (entered in error, etc).
76   croak "FS::realestate_subproperty records should never be deleted";
77 }
78
79 =item replace OLD_RECORD (see L<FS::Record>)
80
81 =item check (see L<FS::Record>)
82
83 =item agent
84
85 Returns the associated agent, if any, for the parent L<FS::realestate_property>
86
87 =cut
88
89 sub agent {
90   shift->property->agent;
91 }
92
93 =item property
94
95 Returns the associated parent L<FS::realestate_property> record
96
97 =cut
98
99 sub property {
100   my $self = shift;
101   exists $self->{property}
102   ? $self->{property}
103   : $self->{property} = qsearchs('realestate_property',$self->propnum);
104 }
105
106 =back
107
108 =head1 SUBROUTINES
109
110 =over 4
111
112 =cut
113
114
115
116
117 =back
118
119 =head1 SEE ALSO
120
121 L<FS::record>, L<FS::realestate_property>, L<FS::svc_realestate>
122
123 =cut
124
125 1;