X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Freason_type.pm;h=4425c64a07693a055681d804891306e049bc7a0c;hp=89278d08a982e7293740e420af7f0bad4408b6ff;hb=74e058c8a010ef6feb539248a550d0bb169c1e94;hpb=ce98306f315a53f2ac4b8c010341c4f84bf728a8 diff --git a/FS/FS/reason_type.pm b/FS/FS/reason_type.pm index 89278d08a..4425c64a0 100644 --- a/FS/FS/reason_type.pm +++ b/FS/FS/reason_type.pm @@ -6,6 +6,18 @@ use FS::Record qw( qsearch qsearchs ); @ISA = qw(FS::Record); +our %class_name = ( + 'C' => 'cancel', + 'R' => 'credit', + 'S' => 'suspend', +); + +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', +); + =head1 NAME FS::reason_type - Object methods for reason_type records @@ -34,7 +46,7 @@ inherits from FS::Record. The following fields are currently supported: =item typenum - primary key -=item class - currently 'C' or 'S' for cancel or suspend +=item class - currently 'C', 'R', or 'S' for cancel, credit, or suspend =item type - name of the type of reason @@ -89,7 +101,7 @@ sub check { 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; @@ -119,6 +131,68 @@ sub enabled_reasons { } ); } +# _populate_initial_data +# +# 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); + } + + ''; + +} + +# _upgrade_data +# +# 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