diff options
author | Jonathan Prykop <jonathan@freeside.biz> | 2016-02-05 15:16:12 -0600 |
---|---|---|
committer | Jonathan Prykop <jonathan@freeside.biz> | 2016-02-05 15:16:12 -0600 |
commit | 9192ae1275e778f890d75c07066ddd2e4cabaa26 (patch) | |
tree | 5251db11c8c76b8cd45f84117e5fa57602ef7d0a /FS/FS/cust_credit.pm | |
parent | ff8a7535a81005b7c66e8e75e5cfa8449a8cef04 (diff) |
RT#39586 Manual check refunds cannot be unapplied
Diffstat (limited to 'FS/FS/cust_credit.pm')
-rw-r--r-- | FS/FS/cust_credit.pm | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index 6b21d69..a598b37 100644 --- a/FS/FS/cust_credit.pm +++ b/FS/FS/cust_credit.pm @@ -1028,6 +1028,58 @@ sub credit_lineitems { } +### refund_to_unapply/unapply_refund false laziness with FS::cust_pay + +=item refund_to_unapply + +Returns L<FS::cust_credit_refund> objects that will be deleted by L</unapply_refund> +(all currently applied refunds that aren't closed.) +Returns empty list if credit itself is closed. + +=cut + +sub refund_to_unapply { + my $self = shift; + return () if $self->closed; + qsearch({ + 'table' => 'cust_credit_refund', + 'hashref' => { 'crednum' => $self->crednum }, + 'addl_from' => 'LEFT JOIN cust_refund USING (refundnum)', + 'extra_sql' => "AND (cust_refund.closed = '' OR cust_refund.closed IS NULL)", + }); +} + +=item unapply_refund + +Deletes all objects returned by L</refund_to_unapply>. + +=cut + +sub unapply_refund { + 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; + + foreach my $cust_credit_refund ($self->refund_to_unapply) { + my $error = $cust_credit_refund->delete; + if ($error) { + dbh->rollback if $oldAutoCommit; + return $error; + } + } + + dbh->commit or die dbh->errstr if $oldAutoCommit; + return ''; +} + =back =head1 SUBROUTINES |