1 package FS::reason_type;
5 use FS::Record qw( qsearch qsearchs );
17 our %class_purpose = (
18 'C' => 'explain why a customer package was cancelled',
19 'R' => 'explain why a customer was credited',
20 'S' => 'explain why a customer package was suspended',
21 'X' => 'explain why a credit was voided',
22 'F' => 'explain why a customer was refunded',
27 FS::reason_type - Object methods for reason_type records
33 $record = new FS::reason_type \%hash;
34 $record = new FS::reason_type { 'column' => 'value' };
36 $error = $record->insert;
38 $error = $new_record->replace($old_record);
40 $error = $record->delete;
42 $error = $record->check;
46 An FS::reason_type object represents a grouping of reasons. FS::reason_type
47 inherits from FS::Record. The following fields are currently supported:
51 =item typenum - primary key
53 =item class - currently 'C', 'R', 'S' or 'X' for cancel, credit, suspend, refund or void credit
55 =item type - name of the type of reason
66 Creates a new reason_type. To add the example to the database, see L<"insert">.
68 Note that this stores the hash reference, not a distinct copy of the hash it
69 points to. You can ask the object for a copy with the I<hash> method.
73 sub table { 'reason_type'; }
77 Adds this record to the database. If there is an error, returns the error,
78 otherwise returns false.
84 Delete this record from the database.
88 =item replace OLD_RECORD
90 Replaces the OLD_RECORD with this one in the database. If there is an error,
91 returns the error, otherwise returns false.
97 Checks all fields to make sure this is a valid reason_type. If there is
98 an error, returns the error, otherwise returns false. Called by the insert
107 $self->ut_numbern('typenum')
108 || $self->ut_enum('class', [ keys %class_name ] )
109 || $self->ut_text('type')
111 return $error if $error;
118 Returns a list of all reasons associated with this type.
123 qsearch( 'reason', { 'reason_type' => shift->typenum } );
126 =item enabled_reasons
128 Returns a list of enabled reasons associated with this type.
132 sub enabled_reasons {
133 qsearch( 'reason', { 'reason_type' => shift->typenum,
138 # Used by FS::Setup to initialize a new database.
139 sub _populate_initial_data { # class method
140 my ($self, %opts) = @_;
142 my $conf = new FS::Conf;
144 foreach ( keys %class_name ) {
145 my $object = $self->new( {'class' => $_,
146 'type' => ucfirst($class_name{$_}). ' Reason',
148 my $error = $object->insert();
149 die "error inserting $self into database: $error\n"
153 my $object = qsearchs('reason_type', { 'class' => 'R' });
154 die "can't find credit reason type just inserted!\n"
157 foreach ( keys %FS::cust_credit::reasontype_map ) {
158 # my $object = $self->new( {'class' => 'R',
159 # 'type' => $FS::cust_credit::reasontype_map{$_},
161 # my $error = $object->insert();
162 # die "error inserting $self into database: $error\n"
164 $conf->set($_, $object->typenum);
171 # Used by FS::Upgrade to migrate to a new database.
172 sub _upgrade_data { # class method
173 my ($self, %opts) = @_;
175 foreach ( keys %class_name ) {
176 unless (scalar(qsearch('reason_type', { 'class' => $_ }))) {
177 my $object = $self->new( {'class' => $_,
178 'type' => ucfirst($class_name{$_}),
180 my $error = $object->insert();
181 die "error inserting $self into database: $error\n"
194 Here be termintes. Don't use on wooden computers.
198 L<FS::Record>, schema.html from the base documentation.