summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2015-08-28 00:56:49 -0500
committerJonathan Prykop <jonathan@freeside.biz>2015-08-28 00:56:49 -0500
commit46bbbb1a78fd822805226abea832b6206273c091 (patch)
treeaedc878b1ee1ca33f065678f61d5805b7c6d9da9 /httemplate
parent76e8fffdfe3b6f6f8ab422038b62e40cc10f95e8 (diff)
RT#37064: Add action link to manually refund a payment
Diffstat (limited to 'httemplate')
-rwxr-xr-xhttemplate/edit/cust_refund.cgi10
-rwxr-xr-xhttemplate/edit/process/cust_refund.cgi31
-rwxr-xr-xhttemplate/misc/unapply-cust_pay.cgi6
-rw-r--r--httemplate/view/cust_main/payment_history.html1
-rw-r--r--httemplate/view/cust_main/payment_history/payment.html13
5 files changed, 26 insertions, 35 deletions
diff --git a/httemplate/edit/cust_refund.cgi b/httemplate/edit/cust_refund.cgi
index fa049a39a..bfcbfe725 100755
--- a/httemplate/edit/cust_refund.cgi
+++ b/httemplate/edit/cust_refund.cgi
@@ -139,16 +139,8 @@ my $payinfo = $cgi->param('payinfo');
my $reason = $cgi->param('reason');
my $link = $cgi->param('popup') ? 'popup' : '';
-my @rights = ();
-push @rights, 'Post refund' if $payby =~ /^(BILL|CASH|MCRD|MCHK)$/;
-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( $paynum, $cust_pay ) = ( '', '' );
if ( $cgi->param('paynum') =~ /^(\d+)$/ ) {
diff --git a/httemplate/edit/process/cust_refund.cgi b/httemplate/edit/process/cust_refund.cgi
index 52fede8ec..ce72c9253 100755
--- a/httemplate/edit/process/cust_refund.cgi
+++ b/httemplate/edit/process/cust_refund.cgi
@@ -12,7 +12,7 @@
</BODY></HTML>
% } 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|MCRD|MCHK)$/;
-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);
$cgi->param('reasonnum') =~ /^(-?\d+)$/ or die "Illegal reasonnum";
my ($reasonnum, $error) = $m->comp('/misc/process/elements/reason');
@@ -63,12 +55,19 @@ if ( $error ) {
'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;
+ }
}
</%init>
diff --git a/httemplate/misc/unapply-cust_pay.cgi b/httemplate/misc/unapply-cust_pay.cgi
index 8cdac180b..b0343d034 100755
--- a/httemplate/misc/unapply-cust_pay.cgi
+++ b/httemplate/misc/unapply-cust_pay.cgi
@@ -12,9 +12,7 @@ my $paynum = $1;
my $cust_pay = qsearchs('cust_pay', { 'paynum' => $paynum } );
my $custnum = $cust_pay->custnum;
-foreach my $cust_bill_pay ( $cust_pay->cust_bill_pay ) {
- my $error = $cust_bill_pay->delete;
- errorpage($error) if $error;
-}
+my $error = $cust_pay->delete_cust_bill_pay;
+errorpage($error) if $error;
</%init>
diff --git a/httemplate/view/cust_main/payment_history.html b/httemplate/view/cust_main/payment_history.html
index e3599bc06..1525e9314 100644
--- a/httemplate/view/cust_main/payment_history.html
+++ b/httemplate/view/cust_main/payment_history.html
@@ -228,6 +228,7 @@ my %opt = (
(
'View invoices', 'Void invoices', 'Unvoid invoices',
'Apply payment', 'Refund credit card payment', 'Refund Echeck payment',
+ 'Post refund', 'Post check refund', 'Post cash refund ', 'Refund payment',
'Credit card void', 'Echeck void', 'Void payments', 'Unvoid payments',
'Delete payment', 'Unapply payment',
'Apply credit', 'Delete credit', 'Unapply credit', 'Void credit', 'Unvoid credit',
diff --git a/httemplate/view/cust_main/payment_history/payment.html b/httemplate/view/cust_main/payment_history/payment.html
index bf88a6607..0ed2f8003 100644
--- a/httemplate/view/cust_main/payment_history/payment.html
+++ b/httemplate/view/cust_main/payment_history/payment.html
@@ -154,18 +154,19 @@ if ( $apply && $opt{'pkg-balances'} && $cust_pay->pkgnum ) {
my $refund = '';
my $refund_days = $opt{'card_refund-days'} || 120;
-my $refund_right = '';
-$refund_right = 'Refund credit card payment' if $cust_pay->payby eq 'CARD';
-$refund_right = 'Refund Echeck payment' if $cust_pay->payby eq 'CHEK';
+my @refund_right = grep { $opt{$_} } $FS::CurrentUser::CurrentUser->refund_rights($cust_pay->payby);
if ( $cust_pay->closed !~ /^Y/i
- && $cust_pay->payby =~ /^(CARD|CHEK)$/
+ && $cust_pay->payby =~ /^(CARD|CHEK|BILL)$/
&& time-$cust_pay->_date < $refund_days*86400
&& $cust_pay->unrefunded > 0
- && $opt{$refund_right}
+ && scalar(@refund_right)
) {
+ my $refundtitle = ($cust_pay->payby =~ /^(CARD|CHEK)$/)
+ ? emt('Send a refund for this payment to the payment gateway')
+ : emt('Record a refund for this payment');
$refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
qq!paynum=!. $cust_pay->paynum. '"'.
- qq! TITLE="! .emt('Send a refund for this payment to the payment gateway')
+ qq! TITLE="! . $refundtitle
. '">' . emt('refund') . '</A>)';
}