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