fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / FS / tower_sector.pm
1 package FS::tower_sector;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearchs ); # qsearch );
6 use FS::tower;
7
8 =head1 NAME
9
10 FS::tower_sector - Object methods for tower_sector records
11
12 =head1 SYNOPSIS
13
14   use FS::tower_sector;
15
16   $record = new FS::tower_sector \%hash;
17   $record = new FS::tower_sector { 'column' => 'value' };
18
19   $error = $record->insert;
20
21   $error = $new_record->replace($old_record);
22
23   $error = $record->delete;
24
25   $error = $record->check;
26
27 =head1 DESCRIPTION
28
29 An FS::tower_sector object represents an example.  FS::tower_sector inherits from
30 FS::Record.  The following fields are currently supported:
31
32 =over 4
33
34 =item sectornum
35
36 primary key
37
38 =item towernum
39
40 towernum
41
42 =item sectorname
43
44 sectorname
45
46 =item ip_addr
47
48 ip_addr
49
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Creates a new example.  To add the example to the database, see L<"insert">.
60
61 Note that this stores the hash reference, not a distinct copy of the hash it
62 points to.  You can ask the object for a copy with the I<hash> method.
63
64 =cut
65
66 # the new method can be inherited from FS::Record, if a table method is defined
67
68 sub table { 'tower_sector'; }
69
70 =item insert
71
72 Adds this record to the database.  If there is an error, returns the error,
73 otherwise returns false.
74
75 =cut
76
77 # the insert method can be inherited from FS::Record
78
79 =item delete
80
81 Delete this record from the database.
82
83 =cut
84
85 # the delete method can be inherited from FS::Record
86
87 =item replace OLD_RECORD
88
89 Replaces the OLD_RECORD with this one in the database.  If there is an error,
90 returns the error, otherwise returns false.
91
92 =cut
93
94 # the replace method can be inherited from FS::Record
95
96 =item check
97
98 Checks all fields to make sure this is a valid example.  If there is
99 an error, returns the error, otherwise returns false.  Called by the insert
100 and replace methods.
101
102 =cut
103
104 # the check method should currently be supplied - FS::Record contains some
105 # data checking routines
106
107 sub check {
108   my $self = shift;
109
110   my $error = 
111     $self->ut_numbern('sectornum')
112     || $self->ut_number('towernum', 'tower', 'towernum')
113     || $self->ut_text('sectorname')
114     || $self->ut_textn('ip_addr')
115   ;
116   return $error if $error;
117
118   $self->SUPER::check;
119 }
120
121 =item tower
122
123 Returns the tower for this sector, as an FS::tower object (see L<FS::tower>).
124
125 =cut
126
127 sub tower {
128   my $self = shift;
129   qsearchs('tower', { 'towernum'=>$self->towernum } );
130 }
131
132 =item description
133
134 Returns a description for this sector including tower name.
135
136 =cut
137
138 sub description {
139   my $self = shift;
140   $self->tower->towername. ' sector '. $self->sectorname;
141 }
142
143 =back
144
145 =head1 BUGS
146
147 =head1 SEE ALSO
148
149 L<FS::tower>, L<FS::Record>, schema.html from the base documentation.
150
151 =cut
152
153 1;
154