From 2cb70470a8e5c3287146008e4ce2c4eb9f242373 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 28 Oct 2009 19:01:18 +0000 Subject: UI changes for credit applications include on the fly tax calculations #4729 --- httemplate/edit/elements/ApplicationCommon.html | 231 ++++++++++++++++++++++-- 1 file changed, 220 insertions(+), 11 deletions(-) (limited to 'httemplate/edit/elements') diff --git a/httemplate/edit/elements/ApplicationCommon.html b/httemplate/edit/elements/ApplicationCommon.html index b46a3c8fe..181430c5a 100644 --- a/httemplate/edit/elements/ApplicationCommon.html +++ b/httemplate/edit/elements/ApplicationCommon.html @@ -39,10 +39,12 @@ Examples: ) -<% include('/elements/header-popup.html', "Apply $src_thing$to" ) %> + +<% include('/elements/header-popup.html', "Apply $src_thing$to", '', 'onLoad="myOnLoadFunction();"') %> <% include('/elements/error.html') %> +

<% $src_thing %> #<% $src_pkeyvalue %>
@@ -57,18 +59,26 @@ Examples: Amount: - <% $money_char %><% $src->amount %> + <% $money_char %><% $src_amount %> + + +% if ($use_sub_dst_thing && $can_change_credit) { + + +% } + + Unapplied amount: - <% $money_char %><% $unapplied %> + <% $money_char %><% $unapplied %> % if ( $src_table eq 'cust_credit' ) { Reason: - <% $src->reason %> + <% $src->reason %> % } @@ -81,10 +91,16 @@ function changed(what) { if ( dst == '' ) { what.form.submit.disabled=true; +%if ($src_pkey eq 'crednum') { + what.form.tax_button.disabled=true; +%} return true; } what.form.submit.disabled=false; +%if ($src_pkey eq 'crednum') { + what.form.tax_button.disabled=false; +%} % foreach my $dst ( @dst ) { @@ -120,14 +136,14 @@ function changed(what) { % my $owed = $taxX->owed; % my $key = &{$key_generator}([ $cbp, 0, { $pkey => $taxX->$pkey } ]); % my $toapp = exists($apphash{ $key }) ? $apphash{ $key }->[1] : 0; - <% &{$row_generator}( $cbp, $taxX->desc, $owed, $toapp, $taxX->$pkey ) %> + <% &{$row_generator}( $key, $cbp, $taxX->desc, $owed, $toapp, $taxX->$pkey ) %> % $total_owed -= $owed; % $amount -= $toapp; % } % $desc .= ' (default)'; % } % if ( $total_owed > 0 ) { - <% &{$row_generator}($cbp, $desc, $total_owed, $amount, '') %> + <% &{$row_generator}($key, $cbp, $desc, $total_owed, $amount, '') %> % } % } % } @@ -143,17 +159,156 @@ function sub_changed(what) { var table = document.getElementById('ApplicationTable'); var i = table.rows.length; while(i-- > 2) { - var amount_input = table.rows[i].getElementsByTagName('input').item(0); - amount += parseFloat( amount_input.value ) || 0; + var inputs = table.rows[i].getElementsByTagName('input'); + if (! inputs.length) { + continue; + } + amount += parseFloat( inputs.item(0).value ) || 0; } what.form.amount.value = parseFloat(amount).toFixed(2); what.form.display_amount.value = parseFloat(amount).toFixed(2); + set_amount_color(what); } + +function set_amount_color(what) { + if (what.form.src_amount.value < what.form.amount.value) { + what.form.display_amount.style.color = '#ff0000'; + } else { + what.form.display_amount.style.color = '#00ff00'; + } +} + Apply to: +% if ($use_sub_dst_thing && $src_pkey eq 'crednum') { +
+<% include( '/elements/xmlhttp.html', + 'url' => $p.'misc/xmlhttp-calculate_taxes.html', + 'subs' => [ 'calculate_taxes' ], + ) + %> + + +%} + @@ -173,7 +328,7 @@ Apply to: % if ($use_sub_dst_thing) { - + % } @@ -184,6 +339,14 @@ Apply to: + + <% include('/elements/footer.html') %> <%init> @@ -209,13 +372,21 @@ my $use_sub_dst_thing = 0; $use_sub_dst_thing = 1 if ( $dst_table eq 'cust_bill' && $conf->exists("${link_table}_pkg-manual") ); +my $can_change_credit = 0; +$can_change_credit = 1 + if ( $src_table eq 'cust_credit' && + $FS::CurrentUser::CurrentUser->access_right('Post credit') && + $FS::CurrentUser::CurrentUser->access_right('Delete credit') + ); + my $to = $dst_table eq 'cust_refund' ? ' to Refund' : ''; -my($src_pkeyvalue, $amount, $dst_pkeyvalue); +my($src_pkeyvalue, $amount, $dst_pkeyvalue, $src_amount); if ( $cgi->param('error') ) { $src_pkeyvalue = $cgi->param($src_pkey); $amount = $cgi->param('amount'); $dst_pkeyvalue = $cgi->param($dst_pkey); + $src_amount = $cgi->param('src_amount'); } else { my($query) = $cgi->keywords; $query =~ /^(\d+)$/; @@ -231,6 +402,8 @@ my $p1 = popurl(1); my $src = qsearchs($src_table, { $src_pkey => $src_pkeyvalue } ); die "$src_thing $src_pkeyvalue not found!" unless $src; +$src_amount = $src->amount unless $cgi->param('error'); + my $unapplied = $src->unapplied; my @dst = sort { $a->_date <=> $b->_date @@ -240,9 +413,11 @@ my @dst = sort { $a->_date <=> $b->_date qsearch($dst_table, { 'custnum' => $src->custnum } ); my $row_generator = sub { - my ($cust_bill_pkg, $desc, $owed, $amount, $taxXnum) = @_; + my ($key, $cust_bill_pkg, $desc, $owed, $amount, $taxXnum) = @_; + my ($num, $s_or_r, $taxlinenum) = split(':', $key); my $id = $cust_bill_pkg->pkgnum || 'Tax'; my $billpkgnum = $cust_bill_pkg->billpkgnum; + my $s_or_r = $cust_bill_pkg->setup > 0 ? 'setup' : 'recur'; $amount = sprintf("%.2f", $amount); qq! @@ -277,6 +452,20 @@ my $row_generator = sub { taxnum_input.setAttribute('rownum', rownum); taxnum_input.setAttribute('value', "$taxXnum"); amount_cell.appendChild(taxnum_input); + var s_or_r_input = document.createElement('INPUT'); + s_or_r_input.setAttribute('name', 's_or_r'+rownum); + s_or_r_input.setAttribute('id', 's_or_r'+rownum); + s_or_r_input.setAttribute('type', 'hidden'); + s_or_r_input.setAttribute('rownum', rownum); + s_or_r_input.setAttribute('value', "$s_or_r"); + amount_cell.appendChild(s_or_r_input); + var itemdesc_input = document.createElement('INPUT'); + itemdesc_input.setAttribute('name', 'itemdesc'+rownum); + itemdesc_input.setAttribute('id', 'itemdesc'+rownum); + itemdesc_input.setAttribute('type', 'hidden'); + itemdesc_input.setAttribute('rownum', rownum); + itemdesc_input.setAttribute('value', "$desc"); + amount_cell.appendChild(itemdesc_input); row.appendChild(pkg_cell); row.appendChild(amount_cell); rownum++; @@ -294,4 +483,24 @@ my $key_generator = sub { join(':', $cust_bill_pkg->billpkgnum, $setup_or_recur, $taxlinenum); }; +my $onload = 'return true;'; + +if ($cgi->param('error')) { + + my $set_sub_amounts = + join(';', map { "myform.subamount$_.value = ". $cgi->param("subamount$_") } + grep { /.+/ } + map { /^subnum(\d+)$/ ? $1 : '' } + $cgi->param + ); + $set_sub_amounts &&= "$set_sub_amounts;sub_changed(myform.subamount0)"; + + $onload = qq! + var myform = document.getElementById('ApplicationForm'); + changed(myform.elements['$dst_pkey']); + $set_sub_amounts; + return true; + !; +} + -- cgit v1.2.1
Amount: <% $money_char %> STYLE="text-align:right;">