1 package FS::reason_type;
5 use FS::Record qw( qsearch qsearchs );
9 tie our %class_name, Tie::IxHash, (
15 'I' => 'void invoice',
16 'P' => 'void payment',
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 'F' => 'explain why a customer was refunded',
24 'X' => 'explain why a credit was voided',
25 'I' => 'explain why an invoice was voided',
26 'P' => 'explain why a payment was voided',
29 our %class_add_access_right = (
30 'C' => 'Add on-the-fly cancel reason',
31 'R' => 'Add on-the-fly credit reason',
32 'S' => 'Add on-the-fly suspend reason',
33 'F' => 'Add on-the-fly refund reason',
34 'X' => 'Add on-the-fly void reason',
35 'I' => 'Add on-the-fly void reason',
36 'P' => 'Add on-the-fly void reason',
41 FS::reason_type - Object methods for reason_type records
47 $record = new FS::reason_type \%hash;
48 $record = new FS::reason_type { 'column' => 'value' };
50 $error = $record->insert;
52 $error = $new_record->replace($old_record);
54 $error = $record->delete;
56 $error = $record->check;
60 An FS::reason_type object represents a grouping of reasons. FS::reason_type
61 inherits from FS::Record. The following fields are currently supported:
65 =item typenum - primary key
67 =item class - one of the keys of %class_name
69 =item type - name of the type of reason
80 Creates a new reason_type. To add the example to the database, see L<"insert">.
82 Note that this stores the hash reference, not a distinct copy of the hash it
83 points to. You can ask the object for a copy with the I<hash> method.
87 sub table { 'reason_type'; }
91 Adds this record to the database. If there is an error, returns the error,
92 otherwise returns false.
98 Delete this record from the database.
102 =item replace OLD_RECORD
104 Replaces the OLD_RECORD with this one in the database. If there is an error,
105 returns the error, otherwise returns false.
111 Checks all fields to make sure this is a valid reason_type. If there is
112 an error, returns the error, otherwise returns false. Called by the insert
121 $self->ut_numbern('typenum')
122 || $self->ut_enum('class', [ keys %class_name ] )
123 || $self->ut_text('type')
125 return $error if $error;
132 Returns a list of all reasons associated with this type.
137 qsearch( 'reason', { 'reason_type' => shift->typenum } );
140 =item enabled_reasons
142 Returns a list of enabled reasons associated with this type.
146 sub enabled_reasons {
147 qsearch( 'reason', { 'reason_type' => shift->typenum,
152 # Used by FS::Setup to initialize a new database.
153 sub _populate_initial_data { # class method
154 my ($self, %opts) = @_;
156 my $conf = new FS::Conf;
158 foreach ( keys %class_name ) {
159 my $object = $self->new( {'class' => $_,
160 'type' => ucfirst($class_name{$_}). ' Reason',
162 my $error = $object->insert();
163 die "error inserting $self into database: $error\n"
167 my $object = qsearchs('reason_type', { 'class' => 'R' });
168 die "can't find credit reason type just inserted!\n"
171 foreach ( keys %FS::cust_credit::reasontype_map ) {
172 # my $object = $self->new( {'class' => 'R',
173 # 'type' => $FS::cust_credit::reasontype_map{$_},
175 # my $error = $object->insert();
176 # die "error inserting $self into database: $error\n"
178 $conf->set($_, $object->typenum);
185 # Used by FS::Upgrade to migrate to a new database.
186 sub _upgrade_data { # class method
187 my ($self, %opts) = @_;
189 foreach ( keys %class_name ) {
190 unless (scalar(qsearch('reason_type', { 'class' => $_ }))) {
191 my $object = $self->new( {'class' => $_,
192 'type' => ucfirst($class_name{$_}),
194 my $error = $object->insert();
195 die "error inserting $self into database: $error\n"
208 Here be termintes. Don't use on wooden computers.
212 L<FS::Record>, schema.html from the base documentation.