rt# 74031 reworked realestate schema as locations and units
[freeside.git] / FS / FS / realestate_unit.pm
1 package FS::realestate_unit;
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_unit - Object representing a realestate_unit record
12
13 =head1 SYNOPSIS
14
15   use FS::realestate_unit;
16
17   $record = new FS:realestate_unit  \%values;
18   $record = new FS::realestate_unit {
19     realestatelocnum => 42,
20     agentnum         => 1,
21     unit_title       => 'Ste 404',
22   };
23
24   $error = $record->insert;
25   $error = $new_rec->replace($record)
26   $error = $record->check;
27
28   $location = $record->location;
29
30 =head1 DESCRIPTION
31
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.
36
37 A FS::realestate_unit object must be associated with a FS::realestate_location
38
39 FS::realestate_unit inherits from FS::Record.
40
41 The following fields are currently supported:
42
43 =over 4
44
45 =item realestatenum
46
47 =item realestatelocnum
48
49 =item agentnum
50
51 =item custnum
52
53 =item unit_title
54
55 =item disabled
56
57 =back
58
59 =head1 METHODS
60
61 =over 4
62
63 =item new HASHREF (see L<FS::Record>)
64
65 =cut
66
67 sub table {'realestate_unit';}
68
69 =item insert (see L<FS::Record>)
70
71 =item delete
72
73   FS::realestate_unit records should never be deleted, only disabled
74
75 =cut
76
77 sub delete {
78   # Once this record has been associated with a customer in any way, it
79   # should not be deleted.  todo perhaps, add a is_deletable function that
80   # checks if the record has ever actually been used, and allows deletion
81   # if it hasn't.  (entered in error, etc).
82   croak "FS::realestate_unit records should never be deleted";
83 }
84
85
86 =item replace OLD_RECORD (see L<FS::Record>)
87
88 =item check (see L<FS::Record>)
89
90 =item agent
91
92 Returns the associated agent, if any, for this object
93
94 =cut
95
96 sub agent {
97   my $self = shift;
98   return undef unless $self->agentnum;
99   return qsearchs('agent', {agentnum => $self->agentnum} );
100 }
101
102 =item location
103
104   Return the associated FS::realestate_location object
105
106 =cut
107
108 sub location {
109   my $self = shift;
110   return $self->{location} if exists $self->{location};
111   return $self->{location} = qsearchs(
112     'realestate_location',
113     {realestatelocnum => $self->realestatelocnum}
114   );
115 }
116
117 =back
118
119 =head1 SUBROUTINES
120
121 =over 4
122
123 =cut
124
125
126 =back
127
128 =head1 SEE ALSO
129
130 L<FS::record>, L<FS::realestate_location>, L<FS::svc_realestate>
131
132 =cut
133
134 1;