X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fprocess%2Fcust_refund.cgi;h=6d6ff389e2f9b8d46618ae31d31818da5e947347;hb=f3738a9fcd588d32eea9b0af6a3e884293c0c6e5;hp=f4cce65359dddbed4a1c978339ab72f09ffee2d3;hpb=fb4ab1073f0d15d660c6cdc4e07afebf68ef3924;p=freeside.git diff --git a/httemplate/edit/process/cust_refund.cgi b/httemplate/edit/process/cust_refund.cgi index f4cce6535..6d6ff389e 100755 --- a/httemplate/edit/process/cust_refund.cgi +++ b/httemplate/edit/process/cust_refund.cgi @@ -12,7 +12,7 @@ % } else { -<% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum") %> +<% $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum;show=payment_history") %> % } %} <%init> @@ -30,16 +30,8 @@ my $link = $cgi->param('popup') ? 'popup' : ''; my $payby = $cgi->param('payby'); -my @rights = (); -push @rights, 'Post refund' if $payby =~ /^(BILL|CASH)$/; -push @rights, 'Post check refund' if $payby eq 'BILL'; -push @rights, 'Post cash refund ' if $payby eq 'CASH'; -push @rights, 'Refund payment' if $payby =~ /^(CARD|CHEK)$/; -push @rights, 'Refund credit card payment' if $payby eq 'CARD'; -push @rights, 'Refund Echeck payment' if $payby eq 'CHEK'; - die "access denied" - unless $FS::CurrentUser::CurrentUser->access_right(\@rights); + unless $FS::CurrentUser::CurrentUser->refund_access_right($payby); my $error = ''; if ( $payby =~ /^(CARD|CHEK)$/ ) { @@ -58,12 +50,19 @@ if ( $payby =~ /^(CARD|CHEK)$/ ) { 'reason' => $reason, %options ); } else { - my $new = new FS::cust_refund ( { - map { - $_, scalar($cgi->param($_)); - } fields('cust_refund') #huh? , 'paynum' ) - } ); - $error = $new->insert; + my %hash = map { + $_, scalar($cgi->param($_)) + } fields('cust_refund'); + my $paynum = $cgi->param('paynum'); + $paynum =~ /^(\d*)$/ or die "Illegal paynum!"; + if ($paynum) { + my $cust_pay = qsearchs('cust_pay',{ 'paynum' => $paynum }); + die "Could not find paynum $paynum" unless $cust_pay; + $error = $cust_pay->refund(\%hash); + } else { + my $new = new FS::cust_refund ( \%hash ); + $error = $new->insert; + } }