This commit was generated by cvs2svn to compensate for changes in r5562,
[freeside.git] / FS / FS / reason_type.pm
1 package FS::reason_type;
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::reason_type - Object methods for reason_type records
12
13 =head1 SYNOPSIS
14
15   use FS::reason_type;
16
17   $record = new FS::reason_type \%hash;
18   $record = new FS::reason_type { '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::reason_type object represents a grouping of reasons.  FS::reason_type
31 inherits from FS::Record.  The following fields are currently supported:
32
33 =over 4
34
35 =item typenum - primary key
36
37 =item class - currently 'C' or 'S' for cancel or suspend 
38
39 =item type - name of the type of reason
40
41
42 =back
43
44 =head1 METHODS
45
46 =over 4
47
48 =item new HASHREF
49
50 Creates a new reason_type.  To add the example to the database, see L<"insert">.
51
52 Note that this stores the hash reference, not a distinct copy of the hash it
53 points to.  You can ask the object for a copy with the I<hash> method.
54
55 =cut
56
57 sub table { 'reason_type'; }
58
59 =item insert
60
61 Adds this record to the database.  If there is an error, returns the error,
62 otherwise returns false.
63
64 =cut
65
66 =item delete
67
68 Delete this record from the database.
69
70 =cut
71
72 =item replace OLD_RECORD
73
74 Replaces the OLD_RECORD with this one in the database.  If there is an error,
75 returns the error, otherwise returns false.
76
77 =cut
78
79 =item check
80
81 Checks all fields to make sure this is a valid reason_type.  If there is
82 an error, returns the error, otherwise returns false.  Called by the insert
83 and replace methods.
84
85 =cut
86
87 sub check {
88   my $self = shift;
89
90   my $error = 
91     $self->ut_numbern('typenum')
92     || $self->ut_enum('class', [ 'C', 'S' ] )
93     || $self->ut_text('type')
94   ;
95   return $error if $error;
96
97   $self->SUPER::check;
98 }
99
100 =item reasons
101
102 Returns a list of all reasons associated with this type.
103
104 =cut
105
106 sub reasons {
107   qsearch( 'reason', { 'reason_type' => shift->typenum } );
108 }
109
110 =item enabled_reasons
111
112 Returns a list of enabled reasons associated with this type.
113
114 =cut
115
116 sub enabled_reasons {
117   qsearch( 'reason', { 'reason_type' => shift->typenum,
118                        'enabled'     => '',
119                      } );
120 }
121
122 =back
123
124 =head1 BUGS
125
126 Here be termintes.  Don't use on wooden computers.
127
128 =head1 SEE ALSO
129
130 L<FS::Record>, schema.html from the base documentation.
131
132 =cut
133
134 1;
135