summaryrefslogtreecommitdiff
path: root/FS/FS/cust_credit_void.pm
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2015-02-16 13:53:20 -0600
committerJonathan Prykop <jonathan@freeside.biz>2015-02-16 13:53:20 -0600
commit251d07aa41b6830a0a2f2a51c14fa94586d843c2 (patch)
treec53f5a96bc595b914187a4c2be0c9a3084bedb98 /FS/FS/cust_credit_void.pm
parent4771a2fe6202aa77d8e6fda10dc2b221899f3941 (diff)
RT#27710: Credit voiding
Diffstat (limited to 'FS/FS/cust_credit_void.pm')
-rw-r--r--FS/FS/cust_credit_void.pm81
1 files changed, 80 insertions, 1 deletions
diff --git a/FS/FS/cust_credit_void.pm b/FS/FS/cust_credit_void.pm
index f76f794..9c92068 100644
--- a/FS/FS/cust_credit_void.pm
+++ b/FS/FS/cust_credit_void.pm
@@ -1,11 +1,12 @@
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 FS::Record qw(qsearchs); # qsearch qsearchs);
use FS::CurrentUser;
use FS::access_user;
use FS::cust_credit;
+use FS::UID qw( dbh );
=head1 NAME
@@ -85,6 +86,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 +98,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<FS::cust_main>).
@@ -111,6 +156,40 @@ 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<FS::reason>) 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;
+}
+
=back
=head1 BUGS