default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / FS / FS / realestate_location.pm
1 package FS::realestate_location;
2 use strict;
3 use warnings;
4 use Carp qw(croak);
5
6 use base 'FS::Record';
7
8 use FS::Record qw(qsearchs qsearch);
9
10 =head1 NAME
11
12 FS::realestate_location - Object representing a realestate_location record
13
14 =head1 SYNOPSIS
15
16   use FS::realestate_location;
17
18   $location = new FS::realestate_location \%values;
19   $location = new FS::realestate_location {
20     agentnum          => 1,
21     location_title    => 'Superdome',
22     address1          => '1500 Sugar Bowl Dr',
23     city              => 'New Orleans',
24     state             => 'LA',
25     zip               => '70112',
26   };
27
28   $error = $location->insert;
29   $error = $new_loc->replace($location);
30   $error = $record->check;
31
32   $error = $location->add_unit('Box Seat No. 42');
33   @units = $location->units;
34
35 =head1 DESCRIPTION
36
37 An FS::realestate_location object represents a location for one or more
38 FS::realestate_unit objects.  Expected to contain at least one unit, as only
39 realestate_unit objects are assignable to packages via
40 L<FS::svc_realestate>.
41
42 FS::realestate_location inherits from FS::Record.
43
44 The following fields are currently supported:
45
46 =over 4
47
48 =item realestatelocnum
49
50 =item agentnum
51
52 =item location_title
53
54 =item address1 (optional)
55
56 =item address2 (optional)
57
58 =item city (optional)
59
60 =item state (optional)
61
62 =item zip (optional)
63
64 =item disabled
65
66 =back
67
68 =head1 METHODS
69
70 =over 4
71
72 =item new HASHREF (see L<FS::Record>)
73
74 =cut
75
76 sub table {'realestate_location';}
77
78 =item insert (see L<FS::Record>)
79
80 =item delete
81
82   FS::realestate_location records should never be deleted, only disabled
83
84 =cut
85
86 sub delete {
87   # Once this record has been associated with a customer in any way, it
88   # should not be deleted.  todo perhaps, add a is_deletable function that
89   # checks if the record has ever actually been used, and allows deletion
90   # if it hasn't.  (entered in error, etc).
91   croak "FS::realestate_location records should never be deleted";
92 }
93
94 =item replace OLD_RECORD (see L<FS::Record>)
95
96 =item check (see L<FS::Record>)
97
98 =item agent
99
100 Returns the associated agent
101
102 =cut
103
104 sub agent {
105   my $self = shift;
106   return undef unless $self->agentnum;
107   return exists $self->{agent}
108   ? $self->{agent}
109   : $self->{agent} = qsearchs('agent', {agentnum => $self->agentnum} );
110 }
111
112
113 =item add_unit UNIT_TITLE
114
115 Create an associated L<FS::realestate_unit> record
116
117 =cut
118
119 sub add_unit {
120   my ($self, $unit_title) = @_;
121   croak "add_unit() requires a \$unit_title parameter" unless $unit_title;
122
123   if (
124     qsearchs('realestate_unit',{
125       realestatelocnum => $self->realestatelocnum,
126       unit_title => $unit_title,
127     })
128   ) {
129     return "Unit Title ($unit_title) has already been used for location (".
130       $self->location_title.")";
131   }
132
133   my $unit = FS::realestate_unit->new({
134     realestatelocnum => $self->realestatelocnum,
135     agentnum         => $self->agentnum,
136     unit_title       => $unit_title,
137   });
138   my $err = $unit->insert;
139   die "Error creating FS::realestate_new record: $err" if $err;
140
141   return;
142 }
143
144
145 =item units
146
147 Returns all units associated with this location
148
149 =cut
150
151 sub units {
152   my $self = shift;
153   return qsearch(
154     'realestate_unit',
155     {realestatelocnum => $self->realestatelocnum}
156   );
157 }
158
159
160 =head1 SUBROUTINES
161
162 =over 4
163
164 =cut
165
166
167
168
169 =back
170
171 =head1 SEE ALSO
172
173 L<FS::record>, L<FS::realestate_unit>, L<FS::svc_realestate>
174
175 =cut
176
177 1;