diff options
-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 | ||||
-rw-r--r-- | httemplate/view/cust_main/payment_history/credit.html | 12 | ||||
-rw-r--r-- | httemplate/view/cust_main/payment_history/payment.html | 10 |
7 files changed, 18 insertions, 15 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; diff --git a/httemplate/view/cust_main/payment_history/credit.html b/httemplate/view/cust_main/payment_history/credit.html index e9b42d300..2a4119614 100644 --- a/httemplate/view/cust_main/payment_history/credit.html +++ b/httemplate/view/cust_main/payment_history/credit.html @@ -45,7 +45,7 @@ if ( scalar(@cust_credit_bill) == 0 if ( $opt{total_unapplied_refunds} > 0 ) { $apply.= ' ('. include( '/elements/popup_link.html', - 'label' => emt('apply to refund'), + 'label' => emt('apply refund'), 'action' => "${p}edit/cust_credit_refund.cgi?". $cust_credit->crednum, 'actionlabel' => emt('Apply credit to refund'), @@ -100,7 +100,7 @@ if ( scalar(@cust_credit_bill) == 0 if ( $opt{total_unapplied_refunds} > 0 ) { $apply.= ' ('. include( '/elements/popup_link.html', - 'label' => emt('apply to refund'), + 'label' => emt('apply refund'), 'action' => "${p}edit/cust_credit_refund.cgi?". $cust_credit->crednum, 'actionlabel' => emt('Apply credit to refund'), @@ -150,20 +150,18 @@ $delete = areyousure_link("${p}misc/delete-cust_credit.cgi?".$cust_credit->credn my $unapply = ''; if ($opt{'Unapply credit'} && !$cust_credit->closed) { - my $refund_to_unapply = $cust_credit->refund_to_unapply; - my $usepre = $refund_to_unapply && @cust_credit_bill; $unapply = areyousure_link("${p}misc/unapply-cust_credit.cgi?".$cust_credit->crednum, emt('Are you sure you want to unapply this credit from invoices?'), emt('Keep this credit, but dissociate it from the invoices it is currently applied against'), - emt('unapply') . ($usepre ? ' ' . emt('invoices') : '') + emt('unapply') ) if @cust_credit_bill; $unapply .= areyousure_link("${p}misc/unapply-cust_credit_refund.cgi?".$cust_credit->crednum, emt('Are you sure you want to unapply this credit from refunds?'), emt('Keep this credit, but dissociate it from the refunds it is currently applied to'), - emt('unapply') . ($usepre ? ' ' . emt('refunds') : '') + emt('unapply refunds') ) - if $refund_to_unapply; + if $cust_credit->refund_to_unapply; } my $reason = $cust_credit->reason; diff --git a/httemplate/view/cust_main/payment_history/payment.html b/httemplate/view/cust_main/payment_history/payment.html index c690a9281..52883856e 100644 --- a/httemplate/view/cust_main/payment_history/payment.html +++ b/httemplate/view/cust_main/payment_history/payment.html @@ -103,7 +103,7 @@ if ($unapplied > 0) { if ( $opt{total_unapplied_refunds} > 0 ) { $apply.= ' ('. include( '/elements/popup_link.html', - 'label' => emt('apply to refund'), + 'label' => emt('apply refund'), 'action' => "${p}edit/cust_pay_refund.cgi?". $cust_pay->paynum, 'actionlabel' => emt('Apply payment to refund'), @@ -204,20 +204,18 @@ $delete = areyousure_link("${p}misc/delete-cust_pay.cgi?".$cust_pay->paynum, my $unapply = ''; if ($opt{'Unapply payment'} && !$cust_pay->closed) { - my $refund_to_unapply = $cust_pay->refund_to_unapply; - my $usepre = $refund_to_unapply && @cust_bill_pay; $unapply = areyousure_link("${p}misc/unapply-cust_pay.cgi?".$cust_pay->paynum, emt('Are you sure you want to unapply this payment from invoices?'), emt('Keep this payment, but dissociate it from the invoices it is currently applied against'), - emt('unapply') . ($usepre ? ' ' . emt('invoices') : '') + emt('unapply') ) if @cust_bill_pay; $unapply .= areyousure_link("${p}misc/unapply-cust_pay_refund.cgi?".$cust_pay->paynum, emt('Are you sure you want to unapply this payment from refunds?'), emt('Keep this payment, but dissociate it from the refunds it is currently applied to'), - emt('unapply') . ($usepre ? ' ' . emt('refunds') : '') + emt('unapply refunds') ) - if $refund_to_unapply; + if $cust_pay->refund_to_unapply; } </%init> |