1 package FS::cust_class;
2 use base qw( FS::class_Common );
6 use FS::Record qw( dbh );
10 FS::cust_class - Object methods for cust_class records
16 $record = new FS::cust_class \%hash;
17 $record = new FS::cust_class { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $new_record->replace($old_record);
23 $error = $record->delete;
25 $error = $record->check;
29 An FS::pkg_class object represents an customer class. Every customer (see
30 L<FS::cust_main>) has, optionally, a customer class. FS::cust_class inherits
31 from FS::Record. The following fields are currently supported:
41 Text name of this customer class
45 Number of associated cust_category (see L<FS::cust_category>)
49 Tax exempt flag, empty or 'Y'. Used when the cust_class-tax_exempt
50 configuration setting is turned on.
54 Disabled flag, empty or 'Y'
64 Creates a new customer class. To add the customer class to the database, see
69 sub table { 'cust_class'; }
70 sub _target_table { 'cust_main'; }
74 Adds this customer class to the database. If there is an error, returns the
75 error, otherwise returns false.
79 Delete this customer class from the database. Only customer classes with no
80 associated customers can be deleted. If there is an error, returns
81 the error, otherwise returns false.
83 =item replace [ OLD_RECORD ]
85 Replaces OLD_RECORD with this one in the database. If there is an error,
86 returns the error, otherwise returns false.
90 Checks all fields to make sure this is a valid customer class. If there is
91 an error, returns the error, otherwise returns false. Called by the insert
99 $self->ut_enum('tax', [ '', 'Y' ])
100 || $self->SUPER::check;
106 Returns the cust_category record associated with this class, or false if there
118 Returns the category name associated with this class, or false if there
136 my( $self, $sql ) = @_;
137 my $statement = "SELECT COUNT(*) FROM cust_main WHERE classnum = ? AND $sql";
138 my $sth = dbh->prepare($statement) or die dbh->errstr." preparing $statement";
139 $sth->execute($self->classnum) or die $sth->errstr. " executing $statement";
140 $sth->fetchrow_arrayref->[0];
143 sub num_prospect { shift->num_sql(FS::cust_main->prospect_sql) }
144 sub num_ordered { shift->num_sql(FS::cust_main->ordered_sql) }
145 sub num_active { shift->num_sql(FS::cust_main->active_sql) }
146 sub num_inactive { shift->num_sql(FS::cust_main->inactive_sql) }
147 sub num_suspended { shift->num_sql(FS::cust_main->susp_sql) }
148 sub num_cancelled { shift->num_sql(FS::cust_main->cancel_sql) }
156 L<FS::cust_main>, L<FS::Record>