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