'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
'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",
});
}
warn " $_ => $options{$_}\n" foreach keys %options;
}
+ return "No reason specified" unless $options{'reasonnum'} =~ /^\d+$/;
+
my %content = ();
###
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}},
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.
'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",
});
}
$self->set('reasonnum', $reason->get('reasonnum'));
$self->set('reason', '');
}
+ $self->set('reasonnum', $reason->reasonnum);
}
if ( $self->crednum ) {
|| $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;
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'),
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'),
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;
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'),
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>