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