1 package FS::reason_type;
5 use FS::Record qw( qsearch qsearchs );
10 tie our %class_name, 'Tie::IxHash', (
16 'I' => 'invoice void',
17 'P' => 'payment void',
20 our %class_purpose = (
21 'C' => 'explain why a customer package was cancelled',
22 'R' => 'explain why a customer was credited',
23 'S' => 'explain why a customer package was suspended',
24 'F' => 'explain why a customer was refunded',
25 'X' => 'explain why a credit was voided',
26 'I' => 'explain why an invoice was voided',
27 'P' => 'explain why a payment was voided',
30 our %class_add_access_right = (
31 'C' => 'Add on-the-fly cancel reason',
32 'R' => 'Add on-the-fly credit reason',
33 'S' => 'Add on-the-fly suspend reason',
34 'F' => 'Add on-the-fly refund reason',
35 'X' => 'Add on-the-fly void reason',
36 'I' => 'Add on-the-fly void reason',
37 'P' => 'Add on-the-fly void reason',
42 FS::reason_type - Object methods for reason_type records
48 $record = new FS::reason_type \%hash;
49 $record = new FS::reason_type { 'column' => 'value' };
51 $error = $record->insert;
53 $error = $new_record->replace($old_record);
55 $error = $record->delete;
57 $error = $record->check;
61 An FS::reason_type object represents a grouping of reasons. FS::reason_type
62 inherits from FS::Record. The following fields are currently supported:
66 =item typenum - primary key
68 =item class - one of the keys of %class_name
70 =item type - name of the type of reason
81 Creates a new reason_type. To add the example to the database, see L<"insert">.
83 Note that this stores the hash reference, not a distinct copy of the hash it
84 points to. You can ask the object for a copy with the I<hash> method.
88 sub table { 'reason_type'; }
92 Adds this record to the database. If there is an error, returns the error,
93 otherwise returns false.
99 Delete this record from the database.
103 =item replace OLD_RECORD
105 Replaces the OLD_RECORD with this one in the database. If there is an error,
106 returns the error, otherwise returns false.
112 Checks all fields to make sure this is a valid reason_type. If there is
113 an error, returns the error, otherwise returns false. Called by the insert
122 $self->ut_numbern('typenum')
123 || $self->ut_enum('class', [ keys %class_name ] )
124 || $self->ut_text('type')
126 return $error if $error;
133 Returns a list of all reasons associated with this type.
138 qsearch( 'reason', { 'reason_type' => shift->typenum } );
141 =item enabled_reasons
143 Returns a list of enabled reasons associated with this type.
147 sub enabled_reasons {
148 qsearch( 'reason', { 'reason_type' => shift->typenum,
153 # Used by FS::Setup to initialize a new database.
154 sub _populate_initial_data { # class method
155 my ($self, %opts) = @_;
157 my $conf = new FS::Conf;
159 foreach ( keys %class_name ) {
160 my $object = $self->new( {'class' => $_,
161 'type' => ucfirst($class_name{$_}). ' Reason',
163 my $error = $object->insert();
164 die "error inserting $self into database: $error\n"
168 my $object = qsearchs('reason_type', { 'class' => 'R' });
169 die "can't find credit reason type just inserted!\n"
172 foreach ( keys %FS::cust_credit::reasontype_map ) {
173 # my $object = $self->new( {'class' => 'R',
174 # 'type' => $FS::cust_credit::reasontype_map{$_},
176 # my $error = $object->insert();
177 # die "error inserting $self into database: $error\n"
179 $conf->set($_, $object->typenum);
186 # Used by FS::Upgrade to migrate to a new database.
187 sub _upgrade_data { # class method
188 my ($self, %opts) = @_;
190 foreach ( keys %class_name ) {
191 unless (scalar(qsearch('reason_type', { 'class' => $_ }))) {
192 my $object = $self->new( {'class' => $_,
193 'type' => ucfirst($class_name{$_}),
195 my $error = $object->insert();
196 die "error inserting $self into database: $error\n"
209 Here be termintes. Don't use on wooden computers.
213 L<FS::Record>, schema.html from the base documentation.