use strict;
use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs );
+use Tie::IxHash;
@ISA = qw(FS::Record);
+tie our %class_name, 'Tie::IxHash', (
+ 'C' => 'cancel',
+ 'R' => 'credit',
+ 'S' => 'suspend',
+ 'F' => 'refund',
+ 'X' => 'credit void',
+ 'I' => 'invoice void',
+ 'P' => 'payment void',
+);
+
+our %class_purpose = (
+ 'C' => 'explain why a customer package was cancelled',
+ 'R' => 'explain why a customer was credited',
+ 'S' => 'explain why a customer package was suspended',
+ 'F' => 'explain why a customer was refunded',
+ 'X' => 'explain why a credit was voided',
+ 'I' => 'explain why an invoice was voided',
+ 'P' => 'explain why a payment was voided',
+);
+
+our %class_add_access_right = (
+ 'C' => 'Add on-the-fly cancel reason',
+ 'R' => 'Add on-the-fly credit reason',
+ 'S' => 'Add on-the-fly suspend reason',
+ 'F' => 'Add on-the-fly refund reason',
+ 'X' => 'Add on-the-fly void reason',
+ 'I' => 'Add on-the-fly void reason',
+ 'P' => 'Add on-the-fly void reason',
+);
+
=head1 NAME
FS::reason_type - Object methods for reason_type records
=item typenum - primary key
-=item class - currently 'C' or 'S' for cancel or suspend
+=item class - one of the keys of %class_name
=item type - name of the type of reason
my $error =
$self->ut_numbern('typenum')
- || $self->ut_enum('class', [ 'C', 'S' ] )
+ || $self->ut_enum('class', [ keys %class_name ] )
|| $self->ut_text('type')
;
return $error if $error;
} );
}
+# Used by FS::Setup to initialize a new database.
+sub _populate_initial_data { # class method
+ my ($self, %opts) = @_;
+
+ my $conf = new FS::Conf;
+
+ foreach ( keys %class_name ) {
+ my $object = $self->new( {'class' => $_,
+ 'type' => ucfirst($class_name{$_}). ' Reason',
+ } );
+ my $error = $object->insert();
+ die "error inserting $self into database: $error\n"
+ if $error;
+ }
+
+ my $object = qsearchs('reason_type', { 'class' => 'R' });
+ die "can't find credit reason type just inserted!\n"
+ unless $object;
+
+ foreach ( keys %FS::cust_credit::reasontype_map ) {
+# my $object = $self->new( {'class' => 'R',
+# 'type' => $FS::cust_credit::reasontype_map{$_},
+# } );
+# my $error = $object->insert();
+# die "error inserting $self into database: $error\n"
+# if $error;
+ $conf->set($_, $object->typenum);
+ }
+
+ '';
+
+}
+
+# Used by FS::Upgrade to migrate to a new database.
+sub _upgrade_data { # class method
+ my ($self, %opts) = @_;
+
+ foreach ( keys %class_name ) {
+ unless (scalar(qsearch('reason_type', { 'class' => $_ }))) {
+ my $object = $self->new( {'class' => $_,
+ 'type' => ucfirst($class_name{$_}),
+ } );
+ my $error = $object->insert();
+ die "error inserting $self into database: $error\n"
+ if $error;
+ }
+ }
+
+ '';
+
+}
+
=back
=head1 BUGS