5a2b360791684424401db90db9eff42af716813a
[freeside.git] / FS / FS / ac.pm
1 package FS::ac;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearchs qsearch );
6 use FS::ac_type;
7 use FS::ac_block;
8
9 @ISA = qw( FS::Record );
10
11 =head1 NAME
12
13 FS::ac - Object methods for ac records
14
15 =head1 SYNOPSIS
16
17   use FS::ac;
18
19   $record = new FS::ac \%hash;
20   $record = new FS::ac { 'column' => 'value' };
21
22   $error = $record->insert;
23
24   $error = $new_record->replace($old_record);
25
26   $error = $record->delete;
27
28   $error = $record->check;
29
30 =head1 DESCRIPTION
31
32 An FS::ac record describes a broadband Access Concentrator, such as a DSLAM
33 or a wireless access point.  FS::ac inherits from FS::Record.  The following 
34 fields are currently supported:
35
36 narf
37
38 =over 4
39
40 =item acnum - primary key
41
42 =item actypenum - AC type, see L<FS::ac_type>
43
44 =item acname - descriptive name for the AC
45
46 =back
47
48 =head1 METHODS
49
50 =over 4
51
52 =item new HASHREF
53
54 Create a new record.  To add the record to the database, see L<"insert">.
55
56 =cut
57
58 sub table { 'ac'; }
59
60 =item insert
61
62 Adds this record to the database.  If there is an error, returns the error,
63 otherwise returns false.
64
65 =item delete
66
67 Deletes this record from the database.  If there is an error, returns the
68 error, otherwise returns false.
69
70 =item replace OLD_RECORD
71
72 Replaces OLD_RECORD with this one in the database.  If there is an error,
73 returns the error, otherwise returns false.
74
75 =item check
76
77 Checks all fields to make sure this is a valid record.  If there is an error,
78 returns the error, otherwise returns false.  Called by the insert and replace
79 methods.
80
81 =cut
82
83 sub check {
84   my $self = shift;
85
86   my $error =
87     $self->ut_numbern('acnum')
88     || $self->ut_number('actypenum')
89     || $self->ut_text('acname');
90   return $error if $error;
91
92   return "Unknown actypenum"
93     unless $self->ac_type;
94   '';
95 }
96
97 =item ac_type
98
99 Returns the L<FS::ac_type> object corresponding to this object.
100
101 =cut
102
103 sub ac_type {
104   my $self = shift;
105   return qsearchs('ac_type', { actypenum => $self->actypenum });
106 }
107
108 =item ac_block
109
110 Returns a list of L<FS::ac_block> objects (address blocks) associated
111 with this object.
112
113 =cut
114
115 sub ac_block {
116   my $self = shift;
117   return qsearch('ac_block', { acnum => $self->acnum });
118 }
119
120 =item ac_field
121
122 Returns a hash of L<FS::ac_field> objects assigned to this object.
123
124 =cut
125
126 sub ac_field {
127   my $self = shift;
128
129   return qsearch('ac_field', { acnum => $self->acnum });
130 }
131
132 =back
133
134 =head1 VERSION
135
136 $Id:
137
138 =head1 BUGS
139
140 =head1 SEE ALSO
141
142 L<FS::svc_broadband>, L<FS::ac>, L<FS::ac_block>, L<FS::ac_field>,  schema.html
143 from the base documentation.
144
145 =cut
146
147 1;
148