1 <% include('/elements/header-popup.html', 'Apply Credit') %>
3 <% include('/elements/error.html') %>
5 <FORM ACTION="<% $p1 %>process/cust_credit_bill.cgi" METHOD=POST>
7 Credit #<B><% $crednum %></B>
8 <INPUT TYPE="hidden" NAME="crednum" VALUE="<% $crednum %>">
10 <BR>Date: <B><% time2str("%D", $cust_credit->_date) %></B>
12 <BR>Amount: $<B><% $cust_credit->amount %></B>
14 <BR>Unapplied amount: $<B><% $credited %></B>
16 <BR>Reason: <B><% $cust_credit->reason %></B>
19 function changed(what) {
20 cust_bill = what.options[what.selectedIndex].value;
22 % foreach my $cust_bill ( @cust_bill ) {
24 if ( cust_bill == <% $cust_bill->invnum %> ) {
25 what.form.amount.value = "<% min($cust_bill->owed, $credited) %>";
30 if ( cust_bill == "Refund" ) {
31 what.form.amount.value = "<% $credited %>";
36 <BR>Invoice #<SELECT NAME="invnum" SIZE=1 onChange="changed(this)">
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 %>
43 <OPTION VALUE="Refund">Refund
46 <BR>Amount $<INPUT TYPE="text" NAME="amount" VALUE="<% $amount %>" SIZE=8 MAXLENGTH=8>
49 <CENTER><INPUT TYPE="submit" VALUE="Apply"></CENTER>
58 unless $FS::CurrentUser::CurrentUser->access_right('Apply credit');
60 my($crednum, $amount, $invnum);
61 if ( $cgi->param('error') ) {
62 #$cust_credit_bill = new FS::cust_credit_bill ( {
63 # map { $_, scalar($cgi->param($_)) } fields('cust_credit_bill')
65 $crednum = $cgi->param('crednum');
66 $amount = $cgi->param('amount');
67 #$refund = $cgi->param('refund');
68 $invnum = $cgi->param('invnum');
70 my($query) = $cgi->keywords;
78 my $otaker = getotaker;
82 my $cust_credit = qsearchs('cust_credit', { 'crednum' => $crednum } );
83 die "credit $crednum not found!" unless $cust_credit;
85 my $credited = $cust_credit->credited;
87 my @cust_bill = sort { $a->_date <=> $b->_date
88 or $a->invnum <=> $b->invnum
90 grep { $_->owed != 0 }
91 qsearch('cust_bill', { 'custnum' => $cust_credit->custnum } );