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