1 <% include('/elements/header-popup.html', 'Apply Payment') %>
3 <% include('/elements/error.html') %>
5 <FORM ACTION="<% $p1 %>process/cust_bill_pay.cgi" METHOD=POST>
7 Payment #<B><% $paynum %></B>
8 <INPUT TYPE="hidden" NAME="paynum" VALUE="<% $paynum %>">
10 <BR>Date: <B><% time2str("%D", $cust_pay->_date) %></B>
12 <BR>Amount: $<B><% $cust_pay->paid %></B>
14 <BR>Unapplied amount: $<B><% $unapplied %></B>
16 <SCRIPT TYPE="text/javascript">
17 function changed(what) {
18 cust_bill = what.options[what.selectedIndex].value;
20 % foreach my $cust_bill ( @cust_bill ) {
22 if ( cust_bill == <% $cust_bill->invnum %> ) {
23 what.form.amount.value = "<% min($cust_bill->owed, $unapplied) %>";
28 if ( cust_bill == "Refund" ) {
29 what.form.amount.value = "<% $unapplied %>";
34 <BR>Invoice #<SELECT NAME="invnum" SIZE=1 onChange="changed(this)">
37 % foreach my $cust_bill ( @cust_bill ) {
38 <OPTION<% $cust_bill->invnum eq $invnum ? ' SELECTED' : '' %> VALUE="<% $cust_bill->invnum %>"><% $cust_bill->invnum %> - <% time2str("%D", $cust_bill->_date) %> - $<% $cust_bill->owed %>
41 <OPTION VALUE="Refund">Refund
44 <BR>Amount $<INPUT TYPE="text" NAME="amount" VALUE="<% $amount %>" SIZE=8 MAXLENGTH=8>
47 <CENTER><INPUT TYPE="submit" VALUE="Apply"></CENTER>
51 <% include('/elements/footer.html') %>
56 unless $FS::CurrentUser::CurrentUser->access_right('Apply payment');
58 my($paynum, $amount, $invnum);
59 if ( $cgi->param('error') ) {
60 $paynum = $cgi->param('paynum');
61 $amount = $cgi->param('amount');
62 $invnum = $cgi->param('invnum');
64 my($query) = $cgi->keywords;
71 my $otaker = getotaker;
75 my $cust_pay = qsearchs('cust_pay', { 'paynum' => $paynum } );
76 die "payment $paynum not found!" unless $cust_pay;
78 my $unapplied = $cust_pay->unapplied;
80 my @cust_bill = sort { $a->_date <=> $b->_date
81 or $a->invnum <=> $b->invnum
83 grep { $_->owed != 0 }
84 qsearch('cust_bill', { 'custnum' => $cust_pay->custnum } );