fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / FS / category_Common.pm
1 package FS::category_Common;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch );
6
7 =head1 NAME
8
9 FS::category_Common - Base class for category (group of classifications) classes
10
11 =head1 SYNOPSIS
12
13 use base qw( FS::category_Common );
14 use FS::class_table; #should use this
15
16 #optional for non-standard names
17 sub _class_table { 'table_name'; } #default is to replace s/category/class/
18
19 =head1 DESCRIPTION
20
21 FS::category_Common is a base class for classes which provide a categorization
22 (group of classifications) for other classes, such as pkg_category or
23 cust_category.
24
25 =item delete
26
27 Deletes this category from the database.  Only categories with no associated
28 classifications can be deleted.  If there is an error, returns the error,
29 otherwise returns false.
30
31 =cut
32
33 sub delete {
34   my $self = shift;
35
36   return "Can't delete a ". $self->table.
37          " with ". $self->_class_table. " records!"
38     if qsearch( $self->_class_table, { 'categorynum' => $self->categorynum } );
39
40   $self->SUPER::delete;
41 }
42
43 =item check
44
45 Checks all fields to make sure this is a valid package category.  If there is an
46 error, returns the error, otherwise returns false.  Called by the insert and
47 replace methods.
48
49 =cut
50
51 sub check {
52   my $self = shift;
53
54   $self->ut_numbern('categorynum')
55     or $self->ut_text('categoryname')
56     or $self->ut_snumbern('weight')
57     or $self->ut_enum('disabled', [ '', 'Y' ])
58     or $self->SUPER::check;
59
60 }
61
62 =back
63
64 =cut
65
66 #defaults
67
68 use vars qw( $_class_table );
69 sub _class_table {
70   return $_class_table if $_class_table;
71   my $self = shift;
72   $_class_table = $self->table;
73   $_class_table =~ s/category/cclass/ # s/_category$/_class/
74     or die "can't determine an automatic class table for $_class_table";
75   $_class_table;
76 }
77
78 =head1 BUGS
79
80 =head1 SEE ALSO
81
82 L<FS::Record>
83
84 =cut
85
86 1;
87