summaryrefslogtreecommitdiff
path: root/FS/FS/cust_pay.pm
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2016-02-05 15:16:12 -0600
committerJonathan Prykop <jonathan@freeside.biz>2016-02-23 08:35:56 -0600
commit1bb85d2484b3d9f45c2b1142951503ff1c54e2e9 (patch)
treefb77f0b5d02a031859afbf1e4e72700b619422ed /FS/FS/cust_pay.pm
parent7d44517cf03a15c0b65b77c01720f3758374af22 (diff)
RT#39586 Manual check refunds cannot be unapplied
Diffstat (limited to 'FS/FS/cust_pay.pm')
-rw-r--r--FS/FS/cust_pay.pm54
1 files changed, 53 insertions, 1 deletions
diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index 4d06862..af76b89 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -903,6 +903,58 @@ sub refund {
return '';
}
+### refund_to_unapply/unapply_refund false laziness with FS::cust_credit
+
+=item refund_to_unapply
+
+Returns L<FS::cust_pay_refund> objects that will be deleted by L</unapply_refund>
+(all currently applied refunds that aren't closed.)
+Returns empty list if payment itself is closed.
+
+=cut
+
+sub refund_to_unapply {
+ my $self = shift;
+ return () if $self->closed;
+ qsearch({
+ 'table' => 'cust_pay_refund',
+ 'hashref' => { 'paynum' => $self->paynum },
+ '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_pay_refund ($self->refund_to_unapply) {
+ my $error = $cust_pay_refund->delete;
+ if ($error) {
+ dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ }
+
+ dbh->commit or die dbh->errstr if $oldAutoCommit;
+ return '';
+}
+
=back
=head1 CLASS METHODS
@@ -990,7 +1042,7 @@ sub batch_insert {
Returns an SQL fragment to retreive the unapplied amount.
-=cut
+=cut
sub unapplied_sql {
my ($class, $start, $end) = @_;