diff options
author | Christopher Burger <burgerc@freeside.biz> | 2018-11-07 11:32:05 -0500 |
---|---|---|
committer | Christopher Burger <burgerc@freeside.biz> | 2018-11-07 11:32:05 -0500 |
commit | 9f1847644038cdf5ca947a47cc3d4202eda0ac22 (patch) | |
tree | e621a9debedfa4fd912aaddb3b24b3b4dc2cc2f8 /httemplate/edit/process | |
parent | 4ae000728a11406595c2b5efb44f1fd19eecc974 (diff) |
RT# 74435 - fixed so payment would auto unapply when doing a batch refund
Diffstat (limited to 'httemplate/edit/process')
-rwxr-xr-x | httemplate/edit/process/cust_refund.cgi | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/httemplate/edit/process/cust_refund.cgi b/httemplate/edit/process/cust_refund.cgi index 1f96456e0..9175eb136 100755 --- a/httemplate/edit/process/cust_refund.cgi +++ b/httemplate/edit/process/cust_refund.cgi @@ -55,6 +55,17 @@ if ( $error ) { my( $cust_pay, $cust_payby, $payinfo, $paycvv, $month, $year, $payname ); my $paymask = ''; + +## get cust pay info if paynum exists +if ( $cgi->param('paynum') > 0) { + $cust_pay = qsearchs({ + 'table' => 'cust_pay', + 'hashref' => { 'paynum' => $cgi->param('paynum') }, + 'select' => 'cust_pay.*, cust_pay_batch.payname ', + 'addl_from' => "left join cust_pay_batch on cust_pay_batch.batchnum = cust_pay.batchnum and cust_pay_batch.custnum = $custnum ", + }); +} + if ( (my $custpaybynum = scalar($cgi->param('custpaybynum'))) > 0 ) { ## @@ -75,12 +86,6 @@ if ( (my $custpaybynum = scalar($cgi->param('custpaybynum'))) > 0 ) { } elsif ( $cgi->param('paynum') > 0) { - $cust_pay = qsearchs({ - 'table' => 'cust_pay', - 'hashref' => { 'paynum' => $cgi->param('paynum') }, - 'select' => 'cust_pay.*, cust_pay_batch.payname ', - 'addl_from' => "left join cust_pay_batch on cust_pay_batch.batchnum = cust_pay.batchnum and cust_pay_batch.custnum = $custnum ", - }); $payinfo = $cust_pay->payinfo; $payname = $cust_pay->payname; @@ -228,6 +233,15 @@ if ( (my $custpaybynum = scalar($cgi->param('custpaybynum'))) > 0 ) { $_, scalar($cgi->param($_)) } fields('cust_refund'); + ## unapply payment before creating refund. + while ( $cust_pay && $cust_pay->unapplied < $refund ) { + my @cust_bill_pay = $cust_pay->cust_bill_pay; + last unless @cust_bill_pay; + my $cust_bill_pay = pop @cust_bill_pay; + my $error = $cust_bill_pay->delete; + last if $error; + } + my $new = new FS::cust_refund ( { 'paynum' => $paynum, %hash, } ); |