POD cleanups
[freeside.git] / FS / FS / usage_class.pm
1 package FS::usage_class;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearch qsearchs );
6
7 @ISA = qw(FS::Record);
8
9 =head1 NAME
10
11 FS::usage_class - Object methods for usage_class records
12
13 =head1 SYNOPSIS
14
15   use FS::usage_class;
16
17   $record = new FS::usage_class \%hash;
18   $record = new FS::usage_class { 'column' => 'value' };
19
20   $error = $record->insert;
21
22   $error = $new_record->replace($old_record);
23
24   $error = $record->delete;
25
26   $error = $record->check;
27
28 =head1 DESCRIPTION
29
30 An FS::usage_class object represents a usage class.  Every rate detail
31 (see L<FS::rate_detail>) has, optionally, a usage class.  FS::usage_class
32 inherits from FS::Record.  The following fields are currently supported:
33
34 =over 4
35
36 =item classnum
37
38 Primary key (assigned automatically for new usage classes)
39
40 =item classname
41
42 Text name of this usage class
43
44 =item disabled
45
46 Disabled flag, empty or 'Y'
47
48
49 =back
50
51 =head1 METHODS
52
53 =over 4
54
55 =item new HASHREF
56
57 Creates a new usage class.  To add the usage class to the database,
58 see L<"insert">.
59
60 Note that this stores the hash reference, not a distinct copy of the hash it
61 points to.  You can ask the object for a copy with the I<hash> method.
62
63 =cut
64
65 sub table { 'usage_class'; }
66
67 =item insert
68
69 Adds this record to the database.  If there is an error, returns the error,
70 otherwise returns false.
71
72 =cut
73
74 =item delete
75
76 Delete this record from the database.
77
78 =cut
79
80 =item replace OLD_RECORD
81
82 Replaces the OLD_RECORD with this one in the database.  If there is an error,
83 returns the error, otherwise returns false.
84
85 =cut
86
87 =item check
88
89 Checks all fields to make sure this is a valid usage class.  If there is
90 an error, returns the error, otherwise returns false.  Called by the insert
91 and replace methods.
92
93 =cut
94
95 sub check {
96   my $self = shift;
97
98   my $error = 
99     $self->ut_numbern('classnum')
100     || $self->ut_text('classname')
101     || $self->ut_enum('disabled', [ '', 'Y' ])
102   ;
103   return $error if $error;
104
105   $self->SUPER::check;
106 }
107
108 sub _populate_initial_data {
109   my ($class, %opts) = @_;
110
111   foreach ("Intrastate", "Interstate", "International") {
112     my $object = $class->new( { 'classname' => $_ } );
113     my $error = $object->insert;
114     die "error inserting $class into database: $error\n"
115       if $error;
116   }
117
118   '';
119
120 }
121
122 sub _upgrade_data {
123   my $class = shift;
124
125   return $class->_populate_initial_data(@_)
126     unless scalar( qsearch( 'usage_class', {} ) );
127
128   '';
129
130 }
131
132 =back
133
134 =head1 BUGS
135
136 =head1 SEE ALSO
137
138 L<FS::Record>, schema.html from the base documentation.
139
140 =cut
141
142 1;
143