correct bad conflict resolution
[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
25 % foreach my $cust_bill ( @cust_bill ) {
26
27   if ( cust_bill == <% $cust_bill->invnum %> ) {
28     what.form.amount.value = "<% min($cust_bill->owed, $credited) %>";
29   }
30
31 % } 
32
33   if ( cust_bill == "Refund" ) {
34     what.form.amount.value = "<% $credited %>";
35   }
36 }
37 </SCRIPT>
38
39 <BR>Invoice #<SELECT NAME="invnum" SIZE=1 onChange="changed(this)">
40 <OPTION VALUE="">
41
42 % foreach my $cust_bill ( @cust_bill ) { 
43   <OPTION<% $cust_bill->invnum eq $invnum ? ' SELECTED' : '' %> VALUE="<% $cust_bill->invnum %>"><% $cust_bill->invnum %> - <% time2str("%D",$cust_bill->_date) %> - $<% $cust_bill->owed %>
44 % } 
45
46 <OPTION VALUE="Refund">Refund
47 </SELECT>
48
49 <BR>Amount $<INPUT TYPE="text" NAME="amount" VALUE="<% $amount %>" SIZE=8 MAXLENGTH=8>
50
51 <BR>
52 <CENTER><INPUT TYPE="submit" VALUE="Apply"></CENTER>
53
54 </FORM>
55 </BODY>
56 </HTML>
57
58 <%init>
59 my($crednum, $amount, $invnum);
60 if ( $cgi->param('error') ) {
61   #$cust_credit_bill = new FS::cust_credit_bill ( {
62   #  map { $_, scalar($cgi->param($_)) } fields('cust_credit_bill')
63   #} );
64   $crednum = $cgi->param('crednum');
65   $amount = $cgi->param('amount');
66   #$refund = $cgi->param('refund');
67   $invnum = $cgi->param('invnum');
68 } else {
69   my($query) = $cgi->keywords;
70   $query =~ /^(\d+)$/;
71   $crednum = $1;
72   $amount = '';
73   #$refund = 'yes';
74   $invnum = '';
75 }
76
77 my $otaker = getotaker;
78
79 my $p1 = popurl(1);
80
81 my $cust_credit = qsearchs('cust_credit', { 'crednum' => $crednum } );
82 die "credit $crednum not found!" unless $cust_credit;
83
84 my $credited = $cust_credit->credited;
85
86 my @cust_bill = sort {    $a->_date  <=> $b->_date
87                        or $a->invnum <=> $b->invnum
88                      }
89                 grep { $_->owed != 0 }
90                 qsearch('cust_bill', { 'custnum' => $cust_credit->custnum } );
91 </%init>
92