diff options
| -rwxr-xr-x | httemplate/edit/cust_refund.cgi | 25 | ||||
| -rwxr-xr-x | httemplate/edit/process/cust_refund.cgi | 24 |
2 files changed, 42 insertions, 7 deletions
diff --git a/httemplate/edit/cust_refund.cgi b/httemplate/edit/cust_refund.cgi index c79c39a80..d3ce167f0 100755 --- a/httemplate/edit/cust_refund.cgi +++ b/httemplate/edit/cust_refund.cgi @@ -33,7 +33,7 @@ % $paydate = '' unless ($paydate =~ /^\d{2,4}-\d{1,2}-01$'/); % } - <BR>Payment + <BR><B>Payment</B> <% ntable("#cccccc", 2) %> <TR> @@ -84,7 +84,7 @@ % } #if $cust_pay -<BR>Refund +<BR><B>Refund</B> <% ntable("#cccccc", 2) %> <TR> @@ -94,21 +94,26 @@ <TR> <TD ALIGN="right">Amount</TD> - <TD BGCOLOR="#ffffff">$<INPUT TYPE="text" NAME="refund" VALUE="<% $refund %>" SIZE=8 MAXLENGTH=9> by <B><% FS::payby->payname($payby) %></B></TD> + <TD BGCOLOR="#ffffff">$<INPUT TYPE="text" NAME="refund" VALUE="<% $refund %>" SIZE=8 MAXLENGTH=9></TD> </TR> % if ( $payby eq 'BILL' ) { <TR> - <TD ALIGN="right">Check #</TD> - <TD COLSPAN=2><INPUT TYPE="text" NAME="payinfo" VALUE="<% $payinfo %>" SIZE=10></TD> + <TD ALIGN="right">Check </TD> + <TD><INPUT TYPE="text" NAME="payinfo" VALUE="<% $payinfo %>" SIZE=10></TD> </TR> % } % elsif ($payby eq 'CHEK' || $payby eq 'CARD') { + <TR> + <TD ALIGN="right">Method</TD> + <TD BGCOLOR="#ffffff"><% FS::payby->payname($real_payby) %> # <% $real_paymask %></TD> + </TR> + % if ( $conf->exists("batch-enable") -% || grep $payby eq $_, $conf->config('batch-enable_payby') +% || grep $real_payby eq $_, $conf->config('batch-enable_payby') % ) { -% if ( grep $payby eq $_, $conf->config('realtime-disable_payby') ) { +% if ( grep $real_payby eq $_, $conf->config('realtime-disable_payby') ) { <INPUT TYPE="hidden" NAME="batch" VALUE="1"> % } else { <TR> @@ -175,6 +180,12 @@ if ( $cgi->param('paynum') =~ /^(\d+)$/ ) { } die "no custnum or paynum specified!" unless $custnum; +my $cust_main = qsearchs( 'cust_main', { 'custnum'=>$custnum } ); +die "unknown custnum $custnum" unless $cust_main; + +my $real_payby = $cust_main->payby; +my $real_paymask = $cust_main->paymask; + my $_date = time; my $p1 = popurl(1); diff --git a/httemplate/edit/process/cust_refund.cgi b/httemplate/edit/process/cust_refund.cgi index 44605bf42..33bc886ba 100755 --- a/httemplate/edit/process/cust_refund.cgi +++ b/httemplate/edit/process/cust_refund.cgi @@ -21,6 +21,8 @@ die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Refund payment') || $FS::CurrentUser::CurrentUser->access_right('Post refund'); +my $conf = new FS::Conf; + $cgi->param('custnum') =~ /^(\d*)$/ or die "Illegal custnum!"; my $custnum = $1; my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ) @@ -51,6 +53,19 @@ if ( $error ) { 'CHEK' => 'electronic check (ACH)', ); +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 ", + }); +} + ## # now run the refund ## @@ -80,6 +95,15 @@ if ( $error ) { $_, 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, } ); |
