RT# 79284 Updated discounts UI for Change Package screen
[freeside.git] / httemplate / misc / void-cust_pay.html
1 %if ( $success ) {
2 <& /elements/header-popup.html, mt("Payment voided") &>
3   <SCRIPT TYPE="text/javascript">
4     window.top.location.reload();
5   </SCRIPT>
6   </BODY>
7 </HTML>
8 %} else {
9 <& /elements/header-popup.html, mt('Void payment')  &>
10
11 <& /elements/error.html &>
12
13 <P ALIGN="center"><B><% mt('Void this payment?') |h %></B>
14
15 <FORM action="<% ${p} %>misc/void-cust_pay.html">
16 <INPUT TYPE="hidden" NAME="paynum" VALUE="<% $paynum %>">
17
18 <TABLE BGCOLOR="#cccccc" BORDER="0" CELLSPACING="2" STYLE="margin-left:auto; margin-right:auto">
19 <& /elements/tr-select-reason.html,
20              'field'          => 'reasonnum',
21              'reason_class'   => 'P',
22              'cgi'            => $cgi
23 &>
24 </TABLE>
25
26 <BR>
27 <P ALIGN="CENTER">
28 <INPUT TYPE="submit" NAME="confirm_void_payment" VALUE="<% mt('Void payment') |h %>"> 
29 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
30 <INPUT TYPE="BUTTON" VALUE="<% mt("Don't void payment") |h %>" onClick="parent.cClick();"> 
31
32 </FORM>
33 </BODY>
34 </HTML>
35
36 %}
37 <%init>
38
39 #untaint paynum
40 my $paynum = $cgi->param('paynum');
41 if ($paynum) {
42   $paynum =~ /^(\d+)$/ || die "Illegal paynum";
43 } else {
44   my($query) = $cgi->keywords;
45   $query =~ /^(\d+)/ || die "Illegal paynum";
46   $paynum = $1;
47 }
48
49 my $cust_pay = qsearchs('cust_pay',{'paynum'=>$paynum}) || die "Payment not found";
50
51 my $right = 'Void payments';
52 $right = 'Credit card void' if $cust_pay->payby eq 'CARD';
53 $right = 'Echeck void'      if $cust_pay->payby eq 'CHEK';
54
55 die "access denied"
56   unless $FS::CurrentUser::CurrentUser->access_right($right);
57
58 my $success = 0;
59 if ($cgi->param('confirm_void_payment')) {
60
61   #untaint reasonnum / create new reason
62   my ($reasonnum, $error) = $m->comp('process/elements/reason');
63   if (!$reasonnum) {
64     $error = 'Reason required';
65   } else {
66     my $reason = qsearchs('reason', { 'reasonnum' => $reasonnum })
67       || die "Reason num $reasonnum not found in database";
68         $error = $cust_pay->void($reason) unless $error;
69   }
70
71   if ($error) {
72     $cgi->param('error',$error);
73   } else {
74     $success = 1;
75   }
76 }
77
78 </%init>