diff options
author | ivan <ivan> | 2006-08-26 12:57:42 +0000 |
---|---|---|
committer | ivan <ivan> | 2006-08-26 12:57:42 +0000 |
commit | 3d484726954a5b91bf1f7f7068e7e15c22fade3e (patch) | |
tree | cd5112a23330aa997e4d45c1bd4b36520387dc7d /httemplate/edit/cust_credit_bill.cgi | |
parent | 33f1aac64b6f373538796ec616280b173f977f97 (diff) |
fix javascript for auto-setting application amount
Diffstat (limited to 'httemplate/edit/cust_credit_bill.cgi')
-rwxr-xr-x | httemplate/edit/cust_credit_bill.cgi | 98 |
1 files changed, 44 insertions, 54 deletions
diff --git a/httemplate/edit/cust_credit_bill.cgi b/httemplate/edit/cust_credit_bill.cgi index 5fdc0ba18..249ba31d0 100755 --- a/httemplate/edit/cust_credit_bill.cgi +++ b/httemplate/edit/cust_credit_bill.cgi @@ -1,44 +1,11 @@ -% -% -%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); -% -% <% header("Apply Credit", '') %> -% 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_credit_bill.cgi" METHOD=POST> -% -%my $cust_credit = qsearchs('cust_credit', { 'crednum' => $crednum } ); -%die "credit $crednum not found!" unless $cust_credit; -% -%my $credited = $cust_credit->credited; -% - Credit #<B><% $crednum %></B> <INPUT TYPE="hidden" NAME="crednum" VALUE="<% $crednum %>"> @@ -50,28 +17,18 @@ Credit #<B><% $crednum %></B> <BR>Unapplied amount: $<B><% $credited %></B> <BR>Reason: <B><% $cust_credit->reason %></B> -% -%my @cust_bill = grep $_->owed != 0, -% qsearch('cust_bill', { 'custnum' => $cust_credit->custnum } ); -% -% - <SCRIPT> 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 < $cust_credit->credited -% ? $cust_bill->owed -% : $cust_credit->credited; -% - - if ( cust_bill == $invnum ) { - what.form.amount.value = "<% $changeto %>"; + + if ( cust_bill == <% $cust_bill->invnum %> ) { + what.form.amount.value = "<% min($cust_bill->owed, $credited) %>"; } -% } +% } if ( cust_bill == "Refund" ) { what.form.amount.value = "<% $credited %>"; @@ -81,13 +38,11 @@ function changed(what) { <BR>Invoice #<SELECT NAME="invnum" SIZE=1 onChange="changed(this)"> <OPTION VALUE=""> -% 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 %> +% 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> @@ -97,6 +52,41 @@ function changed(what) { <CENTER><INPUT TYPE="submit" VALUE="Apply"></CENTER> </FORM> - </BODY> </HTML> + +<%init> +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); + +my $cust_credit = qsearchs('cust_credit', { 'crednum' => $crednum } ); +die "credit $crednum not found!" unless $cust_credit; + +my $credited = $cust_credit->credited; + +my @cust_bill = sort { $a->_date <=> $b->_date + or $a->invnum <=> $b->invnum + } + grep { $_->owed != 0 } + qsearch('cust_bill', { 'custnum' => $cust_credit->custnum } ); +</%init> + |