diff options
author | ivan <ivan> | 2006-08-26 02:20:49 +0000 |
---|---|---|
committer | ivan <ivan> | 2006-08-26 02:20:49 +0000 |
commit | 33f1aac64b6f373538796ec616280b173f977f97 (patch) | |
tree | da216f4e6763df83962f048fd8ad867c83d2c631 /httemplate/edit/cust_bill_pay.cgi | |
parent | d910b7f61a6e4dfcfe57b14bde21158a199d91c2 (diff) |
fix javascript for auto-setting application amount
Diffstat (limited to 'httemplate/edit/cust_bill_pay.cgi')
-rwxr-xr-x | httemplate/edit/cust_bill_pay.cgi | 92 |
1 files changed, 42 insertions, 50 deletions
diff --git a/httemplate/edit/cust_bill_pay.cgi b/httemplate/edit/cust_bill_pay.cgi index 2035e4b64..d27d5c1da 100755 --- a/httemplate/edit/cust_bill_pay.cgi +++ b/httemplate/edit/cust_bill_pay.cgi @@ -1,39 +1,11 @@ -% -% -%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); -% -% <% header("Apply Payment", '') %> -% if ( $cgi->param('error') ) { +% if ( $cgi->param('error') ) { <FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT> <BR><BR> % } - <FORM ACTION="<% $p1 %>process/cust_bill_pay.cgi" METHOD=POST> -% -%my $cust_pay = qsearchs('cust_pay', { 'paynum' => $paynum } ); -%die "payment $paynum not found!" unless $cust_pay; -% -%my $unapplied = $cust_pay->unapplied; -% - Payment #<B><% $paynum %></B> <INPUT TYPE="hidden" NAME="paynum" VALUE="<% $paynum %>"> @@ -43,28 +15,18 @@ Payment #<B><% $paynum %></B> <BR>Amount: $<B><% $cust_pay->paid %></B> <BR>Unapplied amount: $<B><% $unapplied %></B> -% -%my @cust_bill = grep $_->owed != 0, -% qsearch('cust_bill', { 'custnum' => $cust_pay->custnum } ); -% -% - -<SCRIPT> +<SCRIPT TYPE="text/javascript"> function changed(what) { cust_bill = what.options[what.selectedIndex].value; + % foreach my $cust_bill ( @cust_bill ) { -% my $invnum = $cust_bill->invnum; -% my $changeto = $cust_bill->owed < $unapplied -% ? $cust_bill->owed -% : $unapplied; -% - - if ( cust_bill == $invnum ) { - what.form.amount.value = "<% $changeto %>"; - } -% } + if ( cust_bill == <% $cust_bill->invnum %> ) { + what.form.amount.value = "<% min($cust_bill->owed, $unapplied) %>"; + } + +% } if ( cust_bill == "Refund" ) { what.form.amount.value = "<% $unapplied %>"; @@ -74,13 +36,11 @@ function changed(what) { <BR>Invoice #<SELECT NAME="invnum" SIZE=1 onChange="changed(this)"> <OPTION VALUE=""> -% foreach my $cust_bill ( @cust_bill ) { - +% foreach my $cust_bill ( @cust_bill ) { <OPTION<% $cust_bill->invnum eq $invnum ? ' SELECTED' : '' %> VALUE="<% $cust_bill->invnum %>"><% $cust_bill->invnum %> - <% time2str("%D", $cust_bill->_date) %> - $<% $cust_bill->owed %> % } - <OPTION VALUE="Refund">Refund </SELECT> @@ -90,6 +50,38 @@ function changed(what) { <CENTER><INPUT TYPE="submit" VALUE="Apply"></CENTER> </FORM> - </BODY> </HTML> + +<%init> +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); + +my $cust_pay = qsearchs('cust_pay', { 'paynum' => $paynum } ); +die "payment $paynum not found!" unless $cust_pay; + +my $unapplied = $cust_pay->unapplied; + +my @cust_bill = sort { $a->_date <=> $b->_date + or $a->invnum <=> $b->invnum + } + grep { $_->owed != 0 } + qsearch('cust_bill', { 'custnum' => $cust_pay->custnum } ); + + +</%init> + |