%
my($crednum, $amount, $invnum);
if ( $cgi->param('error') ) {
#$cust_credit_bill = new FS::cust_credit_bill ( {
# map { $_, scalar($cgi->param($_)) } fields('cust_credit_bill')
#} );
$crednum = $cgi->param('crednum');
$amount = $cgi->param('amount');
#$refund = $cgi->param('refund');
$invnum = $cgi->param('invnum');
} else {
my($query) = $cgi->keywords;
$query =~ /^(\d+)$/;
$crednum = $1;
$amount = '';
#$refund = 'yes';
$invnum = '';
}
my $otaker = getotaker;
my $p1 = popurl(1);
print header("Apply Credit", '');
print qq!Error: !, $cgi->param('error'),
"
"
if $cgi->param('error');
print <
END
my $cust_credit = qsearchs('cust_credit', { 'crednum' => $crednum } );
die "credit $crednum not found!" unless $cust_credit;
my $credited = $cust_credit->credited;
print "Credit # $crednum".
qq!!.
'
Date: '. time2str("%D", $cust_credit->_date). ''.
'
Amount: $'. $cust_credit->amount. ''.
"
Unapplied amount: \$$credited".
'
Reason: '. $cust_credit->reason. ''
;
my @cust_bill = grep $_->owed != 0,
qsearch('cust_bill', { 'custnum' => $cust_credit->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 < $cust_credit->credited
? $cust_bill->owed
: $cust_credit->credited;
print <
END
print qq!
Invoice #";
print qq!
Amount \$!;
print <
END
print <