1 package FS::reason_type;
5 use FS::Record qw( qsearch qsearchs );
13 'U' => 'activate', #uncancel/unsuspend
19 our %class_purpose = (
20 'C' => 'explain why a customer package was cancelled',
21 'R' => 'explain why a customer was credited',
22 'S' => 'explain why a customer package was suspended',
23 'U' => 'explain why a customer package was unsuspended/uncanceled/activated',
24 'W' => 'explain why a customer package was renewed',
25 'T' => 'explain why a customer package term was changed',
26 'F' => 'explain why a customer was refunded',
31 FS::reason_type - Object methods for reason_type records
37 $record = new FS::reason_type \%hash;
38 $record = new FS::reason_type { 'column' => 'value' };
40 $error = $record->insert;
42 $error = $new_record->replace($old_record);
44 $error = $record->delete;
46 $error = $record->check;
50 An FS::reason_type object represents a grouping of reasons. FS::reason_type
51 inherits from FS::Record. The following fields are currently supported:
55 =item typenum - primary key
57 =item class - currently 'C', 'R', or 'S' for cancel, credit, or suspend
59 =item type - name of the type of reason
70 Creates a new reason_type. To add the example to the database, see L<"insert">.
72 Note that this stores the hash reference, not a distinct copy of the hash it
73 points to. You can ask the object for a copy with the I<hash> method.
77 sub table { 'reason_type'; }
81 Adds this record to the database. If there is an error, returns the error,
82 otherwise returns false.
88 Delete this record from the database.
92 =item replace OLD_RECORD
94 Replaces the OLD_RECORD with this one in the database. If there is an error,
95 returns the error, otherwise returns false.
101 Checks all fields to make sure this is a valid reason_type. If there is
102 an error, returns the error, otherwise returns false. Called by the insert
111 $self->ut_numbern('typenum')
112 || $self->ut_enum('class', [ keys %class_name ] )
113 || $self->ut_text('type')
115 return $error if $error;
122 Returns a list of all reasons associated with this type.
127 qsearch( 'reason', { 'reason_type' => shift->typenum } );
130 =item enabled_reasons
132 Returns a list of enabled reasons associated with this type.
136 sub enabled_reasons {
137 qsearch( 'reason', { 'reason_type' => shift->typenum,
142 # Used by FS::Setup to initialize a new database.
143 sub _populate_initial_data { # class method
144 my ($self, %opts) = @_;
146 my $conf = new FS::Conf;
148 foreach ( keys %class_name ) {
149 my $object = $self->new( {'class' => $_,
150 'type' => ucfirst($class_name{$_}). ' Reason',
152 my $error = $object->insert();
153 die "error inserting $self into database: $error\n"
157 my $object = qsearchs('reason_type', { 'class' => 'R' });
158 die "can't find credit reason type just inserted!\n"
161 foreach ( keys %FS::cust_credit::reasontype_map ) {
162 # my $object = $self->new( {'class' => 'R',
163 # 'type' => $FS::cust_credit::reasontype_map{$_},
165 # my $error = $object->insert();
166 # die "error inserting $self into database: $error\n"
168 $conf->set($_, $object->typenum);
175 # Used by FS::Upgrade to migrate to a new database.
176 sub _upgrade_data { # class method
177 my ($self, %opts) = @_;
179 foreach ( keys %class_name ) {
180 unless (scalar(qsearch('reason_type', { 'class' => $_ }))) {
181 my $object = $self->new( {'class' => $_,
182 'type' => ucfirst($class_name{$_}),
184 my $error = $object->insert();
185 die "error inserting $self into database: $error\n"
198 Here be termintes. Don't use on wooden computers.
202 L<FS::Record>, schema.html from the base documentation.