diff options
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Schema.pm | 1 | ||||
-rw-r--r-- | FS/FS/cust_credit.pm | 2 | ||||
-rw-r--r-- | FS/FS/cust_main/Billing_Realtime.pm | 4 | ||||
-rw-r--r-- | FS/FS/cust_pay.pm | 2 | ||||
-rw-r--r-- | FS/FS/cust_refund.pm | 2 |
5 files changed, 9 insertions, 2 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 774a11f27..3fdd4a81d 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -2144,6 +2144,7 @@ sub tables_hashref { 'paymask', 'varchar', 'NULL', $char_d, '', '', 'paybatch', 'varchar', 'NULL', $char_d, '', '', 'closed', 'char', 'NULL', 1, '', '', + 'source_paynum', 'int', 'NULL', '', '', '', # link to cust_payby, to prevent unapply of gateway-generated refunds # credit card/EFT fields (formerly in paybatch) 'gatewaynum', 'int', 'NULL', '', '', '', # payment_gateway FK 'processor', 'varchar', 'NULL', $char_d, '', '', # module name diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index dfa4b1b1d..bf205aa77 100644 --- a/FS/FS/cust_credit.pm +++ b/FS/FS/cust_credit.pm @@ -1061,7 +1061,7 @@ sub refund_to_unapply { '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)", + 'extra_sql' => "AND cust_refund.closed IS NULL AND cust_refund.source_paynum IS NULL", }); } diff --git a/FS/FS/cust_main/Billing_Realtime.pm b/FS/FS/cust_main/Billing_Realtime.pm index 61acb1d92..58ae97ceb 100644 --- a/FS/FS/cust_main/Billing_Realtime.pm +++ b/FS/FS/cust_main/Billing_Realtime.pm @@ -1382,6 +1382,8 @@ sub realtime_refund_bop { warn " $_ => $options{$_}\n" foreach keys %options; } + return "No reason specified" unless $options{'reasonnum'} =~ /^\d+$/; + my %content = (); ### @@ -1665,6 +1667,7 @@ sub realtime_refund_bop { my $cust_refund = new FS::cust_refund ( { 'custnum' => $self->custnum, 'paynum' => $options{'paynum'}, + 'source_paynum' => $options{'paynum'}, 'refund' => $amount, '_date' => '', 'payby' => $bop_method2payby{$options{method}}, @@ -1678,6 +1681,7 @@ sub realtime_refund_bop { my $error = $cust_refund->insert; if ( $error ) { $cust_refund->paynum(''); #try again with no specific paynum + $cust_refund->source_paynum(''); my $error2 = $cust_refund->insert; if ( $error2 ) { # gah, even with transactions. diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 817e3793a..d0966cafa 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -962,7 +962,7 @@ sub refund_to_unapply { '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)", + 'extra_sql' => "AND cust_refund.closed IS NULL AND cust_refund.source_paynum IS NULL", }); } diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm index 74728a60e..d6cedf54b 100644 --- a/FS/FS/cust_refund.pm +++ b/FS/FS/cust_refund.pm @@ -158,6 +158,7 @@ sub insert { $self->set('reasonnum', $reason->get('reasonnum')); $self->set('reason', ''); } + $self->set('reasonnum', $reason->reasonnum); } if ( $self->crednum ) { @@ -306,6 +307,7 @@ sub check { || $self->ut_numbern('_date') || $self->ut_textn('paybatch') || $self->ut_enum('closed', [ '', 'Y' ]) + || $self->ut_foreign_keyn('source_paynum', 'cust_pay', 'paynum') ; return $error if $error; |