svc_broadband rewrite
[freeside.git] / FS / FS / ac_field.pm
1 package FS::ac_field;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearchs );
6 use FS::part_ac_field;
7 use FS::ac;
8
9 use UNIVERSAL qw( can );
10
11 @ISA = qw( FS::Record );
12
13 =head1 NAME
14
15 FS::ac_field - Object methods for ac_field records
16
17 =head1 SYNOPSIS
18
19   use FS::ac_field;
20
21   $record = new FS::ac_field \%hash;
22   $record = new FS::ac_field { 'column' => 'value' };
23
24   $error = $record->insert;
25
26   $error = $new_record->replace($old_record);
27
28   $error = $record->delete;
29
30   $error = $record->check;
31
32 =head1 DESCRIPTION
33
34 L<FS::ac_field> contains values of fields defined by L<FS::part_ac_field>
35 for an L<FS::ac>.  Values must be of the data type defined by ut_type in
36 L<FS::part_ac_field>.
37 Supported fields as follows:
38
39 =over 4
40
41 =item acfieldpart - Type of ac_field as defined by L<FS::part_ac_field>
42
43 =item acnum - The L<FS::ac> to which this value belongs.
44
45 =item value - The contents of the field.
46
47 =back
48
49 =head1 METHODS
50
51 =over 4
52
53 =item new HASHREF
54
55 Create a new record.  To add the record to the database, see L<"insert">.
56
57 =cut
58
59 sub table { 'ac_field'; }
60
61 =item insert
62
63 Adds this record to the database.  If there is an error, returns the error,
64 otherwise returns false.
65
66 =item delete
67
68 Deletes this record from the database.  If there is an error, returns the
69 error, otherwise returns false.
70
71 =item replace OLD_RECORD
72
73 Replaces OLD_RECORD with this one in the database.  If there is an error,
74 returns the error, otherwise returns false.
75
76 =item check
77
78 Checks all fields to make sure this is a valid record.  If there is an error,
79 returns the error, otherwise returns false.  Called by the insert and replace
80 methods.
81
82 =cut
83
84 sub check {
85   my $self = shift;
86
87   return "acnum must be defined" unless $self->acnum;
88   return "acfieldpart must be defined" unless $self->acfieldpart;
89
90   my $ut_func = $self->can("ut_" . $self->part_ac_field->ut_type);
91   my $error = $self->$ut_func('value');
92
93   return $error if $error;
94
95   ''; #no error
96 }
97
98 =item part_ac_field
99
100 Returns a reference to the L<FS:part_ac_field> that defines this L<FS::ac_field>
101
102 =cut
103
104 sub part_ac_field {
105   my $self = shift;
106
107   return qsearchs('part_ac_field', { acfieldpart => $self->acfieldpart });
108 }
109
110 =item ac
111
112 Returns a reference to the L<FS::ac> to which this L<FS::ac_field> belongs.
113
114 =cut
115
116 sub ac {
117   my $self = shift;
118
119   return qsearchs('ac', { acnum => $self->acnum });
120 }
121
122 =back
123
124 =head1 VERSION
125
126 $Id: 
127
128 =head1 BUGS
129
130 =head1 SEE ALSO
131
132 L<FS::svc_broadband>, L<FS::ac>, L<FS::ac_block>, L<FS::ac_field>,  schema.html
133 from the base documentation.
134
135 =cut
136
137 1;
138