new ACL name in 1.9 right away
[freeside.git] / httemplate / edit / cust_credit_bill.cgi
1 <% include('/elements/header-popup.html', 'Apply Credit') %>
2
3 <% include('/elements/error.html') %>
4
5 <FORM ACTION="<% $p1 %>process/cust_credit_bill.cgi" METHOD=POST>
6
7 Credit #<B><% $crednum %></B>
8 <INPUT TYPE="hidden" NAME="crednum" VALUE="<% $crednum %>">
9
10 <BR>Date: <B><% time2str("%D", $cust_credit->_date) %></B>
11
12 <BR>Amount: $<B><% $cust_credit->amount %></B>
13
14 <BR>Unapplied amount: $<B><% $credited %></B>
15
16 <BR>Reason: <B><% $cust_credit->reason %></B>
17
18 <SCRIPT>
19 function changed(what) {
20   cust_bill = what.options[what.selectedIndex].value;
21
22 % foreach my $cust_bill ( @cust_bill ) {
23
24   if ( cust_bill == <% $cust_bill->invnum %> ) {
25     what.form.amount.value = "<% min($cust_bill->owed, $credited) %>";
26   }
27
28 % } 
29
30   if ( cust_bill == "Refund" ) {
31     what.form.amount.value = "<% $credited %>";
32   }
33 }
34 </SCRIPT>
35
36 <BR>Invoice #<SELECT NAME="invnum" SIZE=1 onChange="changed(this)">
37 <OPTION VALUE="">
38
39 % foreach my $cust_bill ( @cust_bill ) { 
40   <OPTION<% $cust_bill->invnum eq $invnum ? ' SELECTED' : '' %> VALUE="<% $cust_bill->invnum %>"><% $cust_bill->invnum %> - <% time2str("%D",$cust_bill->_date) %> - $<% $cust_bill->owed %>
41 % } 
42
43 <OPTION VALUE="Refund">Refund
44 </SELECT>
45
46 <BR>Amount $<INPUT TYPE="text" NAME="amount" VALUE="<% $amount %>" SIZE=8 MAXLENGTH=8>
47
48 <BR>
49 <CENTER><INPUT TYPE="submit" VALUE="Apply"></CENTER>
50
51 </FORM>
52 </BODY>
53 </HTML>
54
55 <%init>
56
57 die "access denied"
58   unless $FS::CurrentUser::CurrentUser->access_right('Apply credit');
59
60 my($crednum, $amount, $invnum);
61 if ( $cgi->param('error') ) {
62   #$cust_credit_bill = new FS::cust_credit_bill ( {
63   #  map { $_, scalar($cgi->param($_)) } fields('cust_credit_bill')
64   #} );
65   $crednum = $cgi->param('crednum');
66   $amount = $cgi->param('amount');
67   #$refund = $cgi->param('refund');
68   $invnum = $cgi->param('invnum');
69 } else {
70   my($query) = $cgi->keywords;
71   $query =~ /^(\d+)$/;
72   $crednum = $1;
73   $amount = '';
74   #$refund = 'yes';
75   $invnum = '';
76 }
77
78 my $otaker = getotaker;
79
80 my $p1 = popurl(1);
81
82 my $cust_credit = qsearchs('cust_credit', { 'crednum' => $crednum } );
83 die "credit $crednum not found!" unless $cust_credit;
84
85 my $credited = $cust_credit->credited;
86
87 my @cust_bill = sort {    $a->_date  <=> $b->_date
88                        or $a->invnum <=> $b->invnum
89                      }
90                 grep { $_->owed != 0 }
91                 qsearch('cust_bill', { 'custnum' => $cust_credit->custnum } );
92
93 </%init>