eliminate some false laziness in FS::Misc::send_email vs. msg_template/email.pm send_...
[freeside.git] / FS / FS / cust_class.pm
index a811be7..a71bc16 100644 (file)
@@ -1,9 +1,9 @@
 package FS::cust_class;
+use base qw( FS::class_Common );
 
 use strict;
-use base qw( FS::class_Common );
-use FS::cust_main;
 use FS::cust_category;
+use FS::Record qw( dbh );
 
 =head1 NAME
 
@@ -44,6 +44,11 @@ Text name of this customer class
 
 Number of associated cust_category (see L<FS::cust_category>)
 
+=item tax
+
+Tax exempt flag, empty or 'Y'.  Used when the cust_class-tax_exempt
+configuration setting is turned on.
+
 =item disabled
 
 Disabled flag, empty or 'Y'
@@ -86,9 +91,17 @@ Checks all fields to make sure this is a valid customer class.  If there is
 an error, returns the error, otherwise returns false.  Called by the insert
 and replace methods.
 
-=item cust_category
+=cut
 
-=item category
+sub check {
+  my $self = shift;
+
+     $self->ut_enum('tax', [ '', 'Y' ])
+  || $self->SUPER::check;
+
+}
+
+=item cust_category
 
 Returns the cust_category record associated with this class, or false if there
 is none.
@@ -105,8 +118,35 @@ sub cust_category {
 Returns the category name associated with this class, or false if there
 is none.
 
+=item num_prospect
+
+=item num_ordered
+
+=item num_active
+
+=item num_inactive
+
+=item num_suspended
+
+=item num_cancelled
+
 =cut
 
+sub num_sql {
+  my( $self, $sql ) = @_;
+  my $statement = "SELECT COUNT(*) FROM cust_main WHERE classnum = ? AND $sql";
+  my $sth = dbh->prepare($statement) or die dbh->errstr." preparing $statement";
+  $sth->execute($self->classnum) or die $sth->errstr. " executing $statement";
+  $sth->fetchrow_arrayref->[0];
+}
+
+sub num_prospect  { shift->num_sql(FS::cust_main->prospect_sql) }
+sub num_ordered   { shift->num_sql(FS::cust_main->ordered_sql) }
+sub num_active    { shift->num_sql(FS::cust_main->active_sql) }
+sub num_inactive  { shift->num_sql(FS::cust_main->inactive_sql) }
+sub num_suspended { shift->num_sql(FS::cust_main->susp_sql) }
+sub num_cancelled { shift->num_sql(FS::cust_main->cancel_sql) }
+
 =back
 
 =head1 BUGS