a59963a91581faa8a57f58fe277b4e2d6fdbdd9b
[freeside.git] / httemplate / elements / tr-select-payment_options.html
1 <%doc>
2
3 Example:
4
5   include( '/elements/tr-select-payment_options.html',
6
7     #opt - most get used in /elements/tr-amount-fee
8     'custnum'              => 4,     # customer number needed for selecting invoices
9     'prefix'               => 'pre', # prefix to fields and row ID's
10     'amount'               => 1,     # payment amount
11     'process-pkgpart'      => scalar($conf->config('manual_process-pkgpart', $cust_main->agentnum)),
12     'process-display'      => scalar($conf->config('manual_process-display')),
13     'process-skip_first'   => $conf->exists('manual_process-skip_first'),
14     'num_payments'         => scalar($cust_main->cust_pay),
15     'surcharge_percentage' =>
16       ( $payby eq 'CARD'
17           ? scalar($conf->config('credit-card-surcharge-percentage', $cust_main->agentnum))
18           : 0
19       ),
20     'surcharge_flatfee' =>
21       ( $payby eq 'CARD'
22           ? scalar($conf->config('credit-card-surcharge-flatfee', $cust_main->agentnum))
23           : 0
24       ),
25   )
26
27 </%doc>
28
29   <TR STYLE="display:block">
30     <TH ALIGN="right"><% mt('Payment options') |h %></TH>
31     <TD COLSPAN=7>
32      <SELECT
33           ID       = "<% $opt{prefix} %>payment_option"
34           NAME     = "<% $opt{prefix} %>payment_option"
35           onChange = "<% $opt{prefix} %>payment_option_changed(this)"
36           <% $opt{disabled} %>
37         >
38                 <OPTION VALUE="select">Select payment option</OPTION>
39                 <OPTION VALUE="<% $opt{amount} %>">Pay full balance</OPTION>
40                 <OPTION VALUE="invoice">Pay specific invoice</OPTION>
41       <OPTION VALUE="specific">Pay specific amount</OPTION>
42         </SELECT>       
43     </TD>
44   </TR>
45
46   <& /elements/tr-select-invoice.html,
47        'custnum' => $opt{custnum},
48        'prefix'  => $opt{prefix},
49   &>
50
51   <& /elements/tr-amount_fee.html,
52        'row_style'  => 'STYLE="display:none;"',
53        %opt
54   &>
55
56   <SCRIPT TYPE="text/javascript">
57
58       function <% $opt{prefix} %>payment_option_changed(what) {
59
60         var surcharge;
61         if (document.getElementById('surcharge_percentage') || document.getElementById('surcharge_percentage')) {
62           surcharge = (+what.value * +document.getElementById('surcharge_percentage').value) + +document.getElementById('surcharge_flatfee').value;
63         }
64         else { surcharge = 0; }
65         var amount = +what.value + +surcharge;
66         document.getElementById('amount').disabled = true;
67
68         if ( what.value == 'select' ) {
69                 document.getElementById('payment_amount_row').style.display = 'none';
70                 document.getElementById('invoice_row').style.display = 'none';
71           document.getElementById('<% $opt{prefix} %>invoice').value = 'select';
72                 document.getElementById('amount').value = '';
73         }
74         else if ( what.value == 'invoice' ) {
75                 document.getElementById('payment_amount_row').style.display = 'none';
76                 document.getElementById('invoice_row').style.display = 'block';
77                 document.getElementById('amount').value = '';
78         }
79         else if ( what.value == 'specific' ) {
80           document.getElementById('payment_amount_row').style.display = 'block';
81           document.getElementById('invoice_row').style.display = 'none';
82           document.getElementById('<% $opt{prefix} %>invoice').value = 'select';
83           document.getElementById('amount').value = '0.00';
84           document.getElementById('amount').disabled = false;
85           if (document.getElementById('ajax_surcharge_cell')) {
86             document.getElementById('ajax_surcharge_cell').innerHTML = '<FONT SIZE="+1">A credit card surcharge of <% $money_char %>0.00 is included in this payment</FONT>';
87           }
88         }
89         else {
90                 document.getElementById('payment_amount_row').style.display = 'block';
91                 document.getElementById('invoice_row').style.display = 'none';
92           document.getElementById('<% $opt{prefix} %>invoice').value = 'select';
93           document.getElementById('amount').value = amount.toFixed(2);
94           document.getElementById('amount').disabled = false;
95           if (document.getElementById('ajax_surcharge_cell')) {
96             document.getElementById('ajax_surcharge_cell').innerHTML = '<FONT SIZE="+1">A credit card surcharge of <% $money_char %>' + surcharge.toFixed(2) + ' is included in this payment</FONT>';
97           }
98         }
99
100       }
101
102       function <% $opt{prefix} %>invoice_select_changed(what) {
103
104         var surcharge;
105         if (document.getElementById('surcharge_percentage') || document.getElementById('surcharge_percentage')) {
106           surcharge = (+what.value * +document.getElementById('surcharge_percentage').value) + +document.getElementById('surcharge_flatfee').value;
107         }
108         else { surcharge = 0; }
109         var amount = +what.value + +surcharge;
110
111         if ( what.value == 'select' ) {
112           alert("we have select");
113                 document.getElementById('payment_amount_row').style.display = 'none';
114                 document.getElementById('amount').value = '';
115         }
116         else {
117                 document.getElementById('payment_amount_row').style.display = 'block';
118           document.getElementById('amount').value = amount.toFixed(2);
119           document.getElementById('amount').disabled = false;
120           if (document.getElementById('ajax_surcharge_cell')) {
121             document.getElementById('ajax_surcharge_cell').innerHTML = '<FONT SIZE="+1">A credit card surcharge of <% $money_char %>' + surcharge.toFixed(2) + ' is included in this payment</FONT>';
122           }
123         }
124
125       }
126
127 </SCRIPT>
128
129 <%init>
130
131 my %opt = @_;
132
133 my $conf = new FS::Conf;
134 my $money_char = $conf->config('money_char') || '$';
135
136 </%init>