X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_credit_void.pm;h=60beaa655d40e306e8548fa254862a16d406ce8a;hp=f76f79442c6a854660004eb2d4afe97b9a5c3610;hb=57bb423fe457ba4e13726877f53bcdf944f828f8;hpb=32072dbf59a054529f5304574c0f56f9567d14d0 diff --git a/FS/FS/cust_credit_void.pm b/FS/FS/cust_credit_void.pm index f76f79442..60beaa655 100644 --- a/FS/FS/cust_credit_void.pm +++ b/FS/FS/cust_credit_void.pm @@ -1,11 +1,16 @@ package FS::cust_credit_void; -use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::Record ); +use base qw( FS::otaker_Mixin FS::cust_main_Mixin FS::reason_Mixin FS::Record ); use strict; +use vars qw( $me $DEBUG ); use FS::Record qw(qsearchs); # qsearch qsearchs); use FS::CurrentUser; use FS::access_user; use FS::cust_credit; +use FS::UID qw( dbh ); + +$me = '[ FS::cust_credit_void ]'; +$DEBUG = 0; =head1 NAME @@ -85,6 +90,7 @@ sub check { || $self->ut_numbern('void_date') || $self->ut_textn('void_reason') || $self->ut_foreign_keyn('void_usernum', 'access_user', 'usernum') + || $self->ut_foreign_keyn('void_reasonnum', 'reason', 'reasonnum') ; return $error if $error; @@ -96,6 +102,49 @@ sub check { $self->SUPER::check; } +=item unvoid + +"Un-void"s this credit: Deletes the voided credit from the database and adds +back (but does not re-apply) a normal credit. + +=cut + +sub unvoid { + my $self = shift; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $cust_credit = new FS::cust_credit ( { + map { $_ => $self->get($_) } grep { $_ !~ /void/ } $self->fields + } ); + my $error = $cust_credit->insert; + + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $error ||= $self->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + ''; + +} + =item cust_main Returns the parent customer object (see L). @@ -111,6 +160,51 @@ sub void_access_user { qsearchs('access_user', { 'usernum' => $self->void_usernum } ); } +=item void_access_user_name + +Returns the voiding employee name. + +=cut + +sub void_access_user_name { + my $self = shift; + my $user = $self->void_access_user; + return unless $user; + return $user->name; +} + +=item void_reason + +Returns the text of the associated void credit reason (see L) for this voided credit. + +The reason for the original credit remains accessible through the reason method. + +=cut + +sub void_reason { + my ($self, $value, %options) = @_; + my $reason_text; + if ( $self->void_reasonnum ) { + my $reason = FS::reason->by_key($self->void_reasonnum); + $reason_text = $reason->reason; + } else { # in case one of these somehow still exists + $reason_text = $self->get('void_reason'); + } + + return $reason_text; +} + +# _upgrade_data +# +# Used by FS::Upgrade to migrate to a new database. +sub _upgrade_data { # class method + my ( $class, %opts ) = @_; + + warn "$me upgrading $class\n" if $DEBUG; + + $class->_upgrade_reasonnum(%opts); +} + =back =head1 BUGS