X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fprocess%2Fcust_refund.cgi;h=9175eb1367b3f2bd752ced9744afabd6f4242d9a;hb=b71b1576c68bc40ad26592b354feace37a029f0e;hp=1f96456e0c7949a29915107b6bb68486de125bf0;hpb=cfb19dcc27824b46d9f74a7e01b16328c8e66f7f;p=freeside.git 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, } );