1 package FS::usage_class;
5 use FS::Record qw( qsearch qsearchs );
11 FS::usage_class - Object methods for usage_class records
17 $record = new FS::usage_class \%hash;
18 $record = new FS::usage_class { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
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:
38 Primary key (assigned automatically for new usage classes)
42 Text name of this usage class
46 Disabled flag, empty or 'Y'
57 Creates a new usage class. To add the usage class to the database,
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.
65 sub table { 'usage_class'; }
69 Adds this record to the database. If there is an error, returns the error,
70 otherwise returns false.
76 Delete this record from the database.
80 =item replace OLD_RECORD
82 Replaces the OLD_RECORD with this one in the database. If there is an error,
83 returns the error, otherwise returns false.
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
99 $self->ut_numbern('classnum')
100 || $self->ut_text('classname')
101 || $self->ut_enum('disabled', [ '', 'Y' ])
103 return $error if $error;
108 sub _populate_initial_data {
109 my ($class, %opts) = @_;
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"
125 return $class->_populate_initial_data(@_)
126 unless scalar( qsearch( 'usage_class', {} ) );
138 L<FS::Record>, schema.html from the base documentation.