1 package FS::reason_type;
5 use FS::Record qw( qsearch qsearchs );
15 our %class_purpose = (
16 'C' => 'explain why a customer package was cancelled',
17 'R' => 'explain why a customer was credited',
18 'S' => 'explain why a customer package was suspended',
23 FS::reason_type - Object methods for reason_type records
29 $record = new FS::reason_type \%hash;
30 $record = new FS::reason_type { 'column' => 'value' };
32 $error = $record->insert;
34 $error = $new_record->replace($old_record);
36 $error = $record->delete;
38 $error = $record->check;
42 An FS::reason_type object represents a grouping of reasons. FS::reason_type
43 inherits from FS::Record. The following fields are currently supported:
47 =item typenum - primary key
49 =item class - currently 'C', 'R', or 'S' for cancel, credit, or suspend
51 =item type - name of the type of reason
62 Creates a new reason_type. To add the example to the database, see L<"insert">.
64 Note that this stores the hash reference, not a distinct copy of the hash it
65 points to. You can ask the object for a copy with the I<hash> method.
69 sub table { 'reason_type'; }
73 Adds this record to the database. If there is an error, returns the error,
74 otherwise returns false.
80 Delete this record from the database.
84 =item replace OLD_RECORD
86 Replaces the OLD_RECORD with this one in the database. If there is an error,
87 returns the error, otherwise returns false.
93 Checks all fields to make sure this is a valid reason_type. If there is
94 an error, returns the error, otherwise returns false. Called by the insert
103 $self->ut_numbern('typenum')
104 || $self->ut_enum('class', [ keys %class_name ] )
105 || $self->ut_text('type')
107 return $error if $error;
114 Returns a list of all reasons associated with this type.
119 qsearch( 'reason', { 'reason_type' => shift->typenum } );
122 =item enabled_reasons
124 Returns a list of enabled reasons associated with this type.
128 sub enabled_reasons {
129 qsearch( 'reason', { 'reason_type' => shift->typenum,
134 # Used by FS::Setup to initialize a new database.
135 sub _populate_initial_data { # class method
136 my ($self, %opts) = @_;
138 my $conf = new FS::Conf;
140 foreach ( keys %class_name ) {
141 my $object = $self->new( {'class' => $_,
142 'type' => ucfirst($class_name{$_}). ' Reason',
144 my $error = $object->insert();
145 die "error inserting $self into database: $error\n"
149 my $object = qsearchs('reason_type', { 'class' => 'R' });
150 die "can't find credit reason type just inserted!\n"
153 foreach ( keys %FS::cust_credit::reasontype_map ) {
154 # my $object = $self->new( {'class' => 'R',
155 # 'type' => $FS::cust_credit::reasontype_map{$_},
157 # my $error = $object->insert();
158 # die "error inserting $self into database: $error\n"
160 $conf->set($_, $object->typenum);
167 # Used by FS::Upgrade to migrate to a new database.
168 sub _upgrade_data { # class method
169 my ($self, %opts) = @_;
171 foreach ( keys %class_name ) {
172 unless (scalar(qsearch('reason_type', { 'class' => $_ }))) {
173 my $object = $self->new( {'class' => $_,
174 'type' => ucfirst($class_name{$_}),
176 my $error = $object->insert();
177 die "error inserting $self into database: $error\n"
190 Here be termintes. Don't use on wooden computers.
194 L<FS::Record>, schema.html from the base documentation.