ho ho ho, merry XSSmas
[freeside.git] / httemplate / edit / cust_credit_bill.cgi
1 <%  header("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 my($crednum, $amount, $invnum);
57 if ( $cgi->param('error') ) {
58   #$cust_credit_bill = new FS::cust_credit_bill ( {
59   #  map { $_, scalar($cgi->param($_)) } fields('cust_credit_bill')
60   #} );
61   $crednum = $cgi->param('crednum');
62   $amount = $cgi->param('amount');
63   #$refund = $cgi->param('refund');
64   $invnum = $cgi->param('invnum');
65 } else {
66   my($query) = $cgi->keywords;
67   $query =~ /^(\d+)$/;
68   $crednum = $1;
69   $amount = '';
70   #$refund = 'yes';
71   $invnum = '';
72 }
73
74 my $otaker = getotaker;
75
76 my $p1 = popurl(1);
77
78 my $cust_credit = qsearchs('cust_credit', { 'crednum' => $crednum } );
79 die "credit $crednum not found!" unless $cust_credit;
80
81 my $credited = $cust_credit->credited;
82
83 my @cust_bill = sort {    $a->_date  <=> $b->_date
84                        or $a->invnum <=> $b->invnum
85                      }
86                 grep { $_->owed != 0 }
87                 qsearch('cust_bill', { 'custnum' => $cust_credit->custnum } );
88 </%init>
89