%
my($paynum, $amount, $invnum);
if ( $cgi->param('error') ) {
$paynum = $cgi->param('paynum');
$amount = $cgi->param('amount');
$invnum = $cgi->param('invnum');
} else {
my($query) = $cgi->keywords;
$query =~ /^(\d+)$/;
$paynum = $1;
$amount = '';
$invnum = '';
}
my $otaker = getotaker;
my $p1 = popurl(1);
print header("Apply Payment", '');
print qq!Error: !, $cgi->param('error'),
"
"
if $cgi->param('error');
print <
END
my $cust_pay = qsearchs('cust_pay', { 'paynum' => $paynum } );
die "payment $paynum not found!" unless $cust_pay;
my $unapplied = $cust_pay->unapplied;
print "Payment # $paynum".
qq!!.
'
Date: '. time2str("%D", $cust_pay->_date). ''.
'
Amount: $'. $cust_pay->paid. ''.
"
Unapplied amount: \$$unapplied"
;
my @cust_bill = grep $_->owed != 0,
qsearch('cust_bill', { 'custnum' => $cust_pay->custnum } );
print <
function changed(what) {
cust_bill = what.options[what.selectedIndex].value;
END
foreach my $cust_bill ( @cust_bill ) {
my $invnum = $cust_bill->invnum;
my $changeto = $cust_bill->owed < $unapplied
? $cust_bill->owed
: $unapplied;
print <
#END
print "\n";
print qq!
Invoice #";
print qq!
Amount \$!;
print <
END
print <