ACL for hardware class config, RT#85057
[freeside.git] / FS / FS / svc_realestate.pm
1 package FS::svc_realestate;
2 use base qw(FS::svc_Common);
3
4 use strict;
5 use warnings;
6 use vars qw($conf);
7
8 use FS::Record qw(qsearchs qsearch dbh);
9 use Tie::IxHash;
10
11 $FS::UID::callback{'FS::svc_realestate'} = sub {
12   $conf = new FS::Conf;
13 };
14
15 =head1 NAME
16
17 FS::svc_realestate - Object methods for svc_realestate records
18
19 =head1 SYNOPSIS
20
21   {...} TODO
22
23 =head1 DESCRIPTION
24
25 A FS::svc_realestate object represents a billable real estate trasnaction,
26 such as renting a home or office.
27
28 FS::svc_realestate inherits from FS::svc_Common.  The following fields are
29 currently supported:
30
31 =over 4
32
33 =item svcnum - primary key
34
35 =back
36
37 =head1 METHODS
38
39 =over 4
40
41 =item new HASHREF
42
43 Instantiates a new svc_realestate object.
44
45 =cut
46
47 sub table_info {
48   tie my %fields, 'Tie::IxHash',
49     svcnum      => 'Service',
50     realestatenum => {
51       type => 'select-realestate_unit',
52       label => 'Real estate unit',
53     };
54
55   {
56     name            => 'Real estate',
57     name_plural     => 'Real estate services',
58     longname_plural => 'Real estate services',
59     display_weight  => 100,
60     cancel_weight   => 100,
61     fields          => \%fields,
62   };
63 }
64
65 sub table {'svc_realestate'}
66
67 =item label
68
69 Returns a label formatted as:
70   <location_title> <unit_title>
71
72 =cut
73
74 sub label {
75   my $self = shift;
76   my $unit = $self->realestate_unit;
77   my $location = $self->realestate_location;
78
79   return $location->location_title.' '.$unit->unit_title
80     if $unit && $location;
81
82   return $self->svcnum; # shouldn't happen
83 }
84
85
86 =item realestate_unit
87
88 Returns associated L<FS::realestate_unit>
89
90 =cut
91
92 sub realestate_unit {
93   my $self = shift;
94
95   return $self->get('_realestate_unit')
96     if $self->get('_realestate_unit');
97
98   return unless $self->realestatenum;
99
100   my $realestate_unit = qsearchs(
101     'realestate_unit',
102     {realestatenum => $self->realestatenum}
103   );
104
105   $self->set('_realestate_unit', $realestate_unit);
106   $realestate_unit;
107 }
108
109 =item realestate_location
110
111 Returns associated L<FS::realestate_location>
112
113 =cut
114
115 sub realestate_location {
116   my $self = shift;
117
118   my $realestate_unit = $self->realestate_unit;
119   return unless $realestate_unit;
120
121   $realestate_unit->location;
122 }
123
124 =item cust_svc
125
126 Returns associated L<FS::cust_svc>
127
128 =cut
129
130 sub cust_svc {
131   qsearchs('cust_svc', { 'svcnum' => $_[0]->svcnum } );
132 }
133
134 =item search_sql
135
136 I have an unfounded suspicion this method serves no purpose in this context
137
138 =cut
139
140 # sub search_sql {die "search_sql called on FS::svc_realestate"}
141
142 =item insert
143
144 Adds this record to the database.  If there is an error, returns the error,
145 otherwise returns false.
146
147 =item delete
148
149 Delete this record from the database.
150
151 =item replace OLD_RECORD
152
153 Replaces the OLD_RECORD with this one in the database.  If there is an error,
154 returns the error, otherwise returns false.
155
156 =item check
157
158 Checks all fields to make sure this is a valid record.  If there is
159 an error, returns the error, otherwise returns false.  Called by the insert
160 and replace methods.
161
162 =back 4
163
164 =head1 BUGS
165
166 =head1 SEE ALSO
167
168 L<FS::Record>, schema.html from the base documentation.
169
170 =cut
171
172 1;