initial version
[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 =over 4
37
38 =item acnum - primary key
39
40 =item actypenum - AC type, see L<FS::ac_type>
41
42 =item acname - descriptive name for the AC
43
44 =back
45
46 =head1 METHODS
47
48 =over 4
49
50 =item new HASHREF
51
52 Create a new record.  To add the record to the database, see L<"insert">.
53
54 =cut
55
56 sub table { 'ac'; }
57
58 =item insert
59
60 Adds this record to the database.  If there is an error, returns the error,
61 otherwise returns false.
62
63 =item delete
64
65 Deletes this record from the database.  If there is an error, returns the
66 error, otherwise returns false.
67
68 =item replace OLD_RECORD
69
70 Replaces OLD_RECORD with this one in the database.  If there is an error,
71 returns the error, otherwise returns false.
72
73 =item check
74
75 Checks all fields to make sure this is a valid record.  If there is an error,
76 returns the error, otherwise returns false.  Called by the insert and replace
77 methods.
78
79 =cut
80
81 sub check {
82   my $self = shift;
83
84   my $error =
85     $self->ut_numbern('acnum')
86     || $self->ut_number('actypenum')
87     || $self->ut_text('acname');
88   return $error if $error;
89
90   return "Unknown actypenum"
91     unless $self->ac_type;
92   '';
93 }
94
95 =item ac_type
96
97 Returns the L<FS::ac_type> object corresponding to this object.
98
99 =cut
100
101 sub ac_type {
102   my $self = shift;
103   return qsearchs('ac_type', { actypenum => $self->actypenum });
104 }
105
106 =item ac_block
107
108 Returns a list of L<FS::ac_block> objects (address blocks) associated
109 with this object.
110
111 =cut
112
113 sub ac_block {
114   my $self = shift;
115   return qsearch('ac_block', { acnum => $self->acnum });
116 }
117
118 =item ac_field
119
120 Returns a hash of L<FS::ac_field> objects assigned to this object.
121
122 =cut
123
124 sub ac_field {
125   my $self = shift;
126
127   return qsearch('ac_field', { acnum => $self->acnum });
128 }
129
130 =back
131
132 =head1 VERSION
133
134 $Id:
135
136 =head1 BUGS
137
138 =head1 SEE ALSO
139
140 L<FS::svc_broadband>, L<FS::ac>, L<FS::ac_block>, L<FS::ac_field>,  schema.html
141 from the base documentation.
142
143 =cut
144
145 1;
146