should log to our db
[freeside.git] / httemplate / elements / tr-amount_fee.html
1   <TR ID="payment_amount_row" <% $opt{'row_style'} %>>
2     <TH ALIGN="right"><% mt('Payment amount') |h %></TH>
3     <TD COLSPAN=7>
4       <TABLE><TR><TD BGCOLOR="#ffffff">
5         <% $money_char %><INPUT NAME     = "amount"
6                                 ID       = "amount"
7                                 TYPE     = "text"
8                                 VALUE    = "<% $amount %>"
9                                 SIZE     = 8
10                                 STYLE    = "text-align:right;"
11 %                               if ( $fee ) {
12                                   onChange   = "amount_changed(this)"
13                                   onKeyDown  = "amount_changed(this)"
14                                   onKeyUp    = "amount_changed(this)"
15                                   onKeyPress = "amount_changed(this)"
16 %                               }
17                          >
18       </TD><TD BGCOLOR="<% length($fee) ? '#cccccc' : '#ffffff' %>">
19 %        if ( $fee ) {
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 %>
24            </B>
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>
29   
30 %        }
31       </TD></TR></TABLE>
32     </TD>
33   </TR>
34
35 % if ( $fee ) {
36
37     <SCRIPT TYPE="text/javascript">
38
39       function amount_changed(what) {
40
41
42         var total = '';
43         if ( what.value.length ) {
44           total = parseFloat(what.value) <% $fee_op %> <% $fee %>;
45           /* total = Math.round(total*100)/100; */
46           total = '<% $money_char %>' + total.toFixed(2);
47         }
48
49         var total_cell = document.getElementById('ajax_total_cell');
50         total_cell.innerHTML = '<FONT SIZE="+1">' + total + ' <% $fee_display eq 'add' ? 'TOTAL' : 'AVAILABLE' %></FONT>';
51
52       }
53
54     </SCRIPT>
55
56 % }
57
58 <%init>
59
60 my %opt = @_;
61
62 my $conf = new FS::Conf;
63 my $money_char = $conf->config('money_char') || '$';
64
65 my $fee = '';
66 my $fee_pkg = '';
67 my $fee_display = '';
68 my $fee_op = '';
69
70 if ( $opt{'process-pkgpart'}
71      and ! $opt{'process-skip_first'} || $opt{'num_payments'}
72    )
73 {
74
75   $fee_display = $opt{'process-display'} || 'add';
76   $fee_op = $fee_display eq 'add' ? '+' : '-';
77
78   $fee_pkg =
79     qsearchs('part_pkg', { pkgpart=>$opt{'process-pkgpart'} } );
80
81   #well ->unit_setup or ->calc_setup both call for a $cust_pkg
82   # (though ->unit_setup doesn't use it...)
83   $fee = $fee_pkg->option('setup_fee')
84     if $fee_pkg; #in case.. better than dying with a perl traceback
85
86 }
87
88 my $amount = $opt{'amount'};
89 if ( $amount > 0 ) {
90   $amount += $fee
91     if $fee && $fee_display eq 'subtract';
92
93   #&{ $opt{post_fee_callback} }( \$amount ) if $opt{post_fee_callback};
94   $amount += $amount * $opt{'surcharge_percentage'}/100
95     if $opt{'surcharge_percentage'} > 0;
96
97   $amount = sprintf("%.2f", $amount);
98 }
99
100 </%init>