1 <TR ID="payment_amount_row">
2 <TH ALIGN="right"><% mt('Payment amount') |h %></TH>
4 <TABLE><TR><TD BGCOLOR="#ffffff">
5 <% $money_char %><INPUT NAME = "amount"
8 VALUE = "<% $amount %>"
10 STYLE = "text-align:right;"
11 % if ( $fee || $surcharge_percentage || $surcharge_flatfee ) {
12 onChange = "amount_changed(this)"
13 onKeyDown = "amount_changed(this)"
14 onKeyUp = "amount_changed(this)"
15 onKeyPress = "amount_changed(this)"
18 </TD><TD BGCOLOR="<% length($fee) ? '#cccccc' : '#ffffff' %>">
20 <INPUT TYPE="hidden" NAME="fee_pkgpart" VALUE="<% $fee_pkg->pkgpart %>">
21 <INPUT TYPE="hidden" NAME="fee" VALUE="<% $fee_display eq 'add' ? $fee : '' %>">
22 <B><FONT SIZE='+1'><% $fee_op %></FONT>
23 <% $money_char . $fee %>
25 <% $fee_pkg->pkg |h %>
26 <B><FONT SIZE='+1'>=</FONT></B>
27 </TD><TD ID="ajax_total_cell" BGCOLOR="#dddddd" STYLE="border:1px solid blue">
28 <FONT SIZE="+1"><% length($amount) ? $money_char. sprintf('%.2f', ($fee_display eq 'add') ? $amount + $fee : $amount - $fee ) : '' %> <% $fee_display eq 'add' ? 'TOTAL' : 'AVAILABLE' %></FONT>
31 % if ( $surcharge_percentage || $surcharge_flatfee ) {
32 <INPUT TYPE="hidden" NAME="surcharge_percentage" ID="surcharge_percentage" VALUE="<% $surcharge_percentage %>">
33 <INPUT TYPE="hidden" NAME="surcharge_flatfee" ID="surcharge_flatfee" VALUE="<% $surcharge_flatfee %>">
34 </TD><TD ID="ajax_surcharge_cell" BGCOLOR="#dddddd" STYLE="border:1px solid blue">
35 <FONT SIZE="+1">A credit card surcharge of <% $money_char. sprintf('%.2f', $surcharge) %> is included in this payment</FONT>
41 % if ($fee || $surcharge_percentage || $surcharge_flatfee ) {
43 <SCRIPT TYPE="text/javascript">
45 function amount_changed(what) {
49 if ( what.value.length ) {
50 total = parseFloat(what.value) <% $fee_op %> <% $fee %>;
51 /* total = Math.round(total*100)/100; */
52 total = '<% $money_char %>' + total.toFixed(2);
55 var total_cell = document.getElementById('ajax_total_cell');
56 total_cell.innerHTML = '<FONT SIZE="+1">' + total + ' <% $fee_display eq 'add' ? 'TOTAL' : 'AVAILABLE' %></FONT>';
59 % if ( $surcharge_percentage || $surcharge_flatfee ) {
60 var surcharge_cell = document.getElementById('ajax_surcharge_cell');
61 var surcharge = ((what.value - <% $surcharge_flatfee %>) * <% $surcharge_percentage %>) + <% $surcharge_flatfee %>;
62 surcharge_cell.innerHTML = '<FONT SIZE="+1">A credit card surcharge of ' + surcharge.toFixed(2) + ' is included in this payment</FONT>';
75 my $conf = new FS::Conf;
76 my $money_char = $conf->config('money_char') || '$';
83 my $surcharge_percentage = 0;
84 my $surcharge_flatfee = 0;
86 if ( $opt{'process-pkgpart'}
87 and ! $opt{'process-skip_first'} || $opt{'num_payments'}
91 $fee_display = $opt{'process-display'} || 'add';
92 $fee_op = $fee_display eq 'add' ? '+' : '-';
95 qsearchs('part_pkg', { pkgpart=>$opt{'process-pkgpart'} } );
97 #well ->unit_setup or ->calc_setup both call for a $cust_pkg
98 # (though ->unit_setup doesn't use it...)
99 $fee = $fee_pkg->option('setup_fee')
100 if $fee_pkg; #in case.. better than dying with a perl traceback
104 my $amount = $opt{'amount'};
106 # probably should not happen, but will prevent surcharge being applied to negative due amounts
107 unless ($amount > 0) { $amount = 0; }
110 if $fee && $fee_display eq 'subtract';
112 #&{ $opt{post_fee_callback} }( \$amount ) if $opt{post_fee_callback};
114 $surcharge_percentage = $opt{'surcharge_percentage'}/100 if $opt{'surcharge_percentage'} > 0;
115 $surcharge_flatfee = $opt{'surcharge_flatfee'} if $opt{'surcharge_flatfee'} > 0;
116 $surcharge = $amount * $surcharge_percentage if $surcharge_percentage > 0;
117 $surcharge += $surcharge_flatfee if ( $surcharge_flatfee > 0 && $amount > 0 );
119 $amount += $surcharge;
121 $amount = sprintf("%.2f", $amount);