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