summaryrefslogtreecommitdiff
path: root/httemplate/elements/tr-select-payment_options.html
blob: 15f92775a4dc35f41a4e3cb6e8231c6b4a83dacb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<%doc>

Example:

  include( '/elements/tr-select-payment_options.html',

    #opt - most get used in /elements/tr-amount-fee
    'custnum'              => 4,     # customer number needed for selecting invoices
    'prefix'               => 'pre', # prefix to fields and row ID's
    'amount'               => 1,     # payment amount
    'process-pkgpart'      => scalar($conf->config('manual_process-pkgpart', $cust_main->agentnum)),
    'process-display'      => scalar($conf->config('manual_process-display')),
    'process-skip_first'   => $conf->exists('manual_process-skip_first'),
    'num_payments'         => scalar($cust_main->cust_pay),
    'surcharge_percentage' =>
      ( $payby eq 'CARD'
          ? scalar($conf->config('credit-card-surcharge-percentage', $cust_main->agentnum))
          : 0
      ),
    'surcharge_flatfee' =>
      ( $payby eq 'CARD'
          ? scalar($conf->config('credit-card-surcharge-flatfee', $cust_main->agentnum))
          : 0
      ),
  )

</%doc>

  <TR STYLE="display:block">
    <TH ALIGN="right"><% mt('Payment options') |h %></TH>
    <TD COLSPAN=7>
     <SELECT
  	  ID       = "<% $opt{prefix} %>payment_option"
  	  NAME     = "<% $opt{prefix} %>payment_option"
  	  onChange = "<% $opt{prefix} %>payment_option_changed(this)"
  	  <% $opt{disabled} %>
	>
  		<OPTION VALUE="select">Select payment option</OPTION>
  		<OPTION VALUE="<% $opt{amount} %>">Pay full balance</OPTION>
  		<OPTION VALUE="invoice">Pay specific invoice</OPTION>
      <OPTION VALUE="specific">Pay specific amount</OPTION>
	</SELECT>	
    </TD>
  </TR>

  <& /elements/tr-select-invoice.html,
       'custnum' => $opt{custnum},
       'prefix'  => $opt{prefix},
  &>

  <& /elements/tr-amount_fee.html,
       'row_style'  => 'STYLE="display:none;"',
       %opt
  &>

  <SCRIPT TYPE="text/javascript">

      function <% $opt{prefix} %>payment_option_changed(what) {

        var surcharge;
        if (document.getElementById('surcharge_percentage') || document.getElementById('surcharge_percentage')) {
          surcharge = (+what.value * +document.getElementById('surcharge_percentage').value) + +document.getElementById('surcharge_flatfee').value;
        }
        else { surcharge = 0; }
        var amount = +what.value + +surcharge;
        document.getElementById('amount').disabled = true;

        if ( what.value == 'select' ) {
        	document.getElementById('payment_amount_row').style.display = 'none';
        	document.getElementById('invoice_row').style.display = 'none';
          document.getElementById('<% $opt{prefix} %>invoice').value = 'select';
        	document.getElementById('amount').value = '';
        }
        else if ( what.value == 'invoice' ) {
        	document.getElementById('payment_amount_row').style.display = 'none';
        	document.getElementById('invoice_row').style.display = 'block';
        	document.getElementById('amount').value = '';
        }
        else if ( what.value == 'specific' ) {
          document.getElementById('payment_amount_row').style.display = 'block';
          document.getElementById('invoice_row').style.display = 'none';
          document.getElementById('<% $opt{prefix} %>invoice').value = 'select';
          document.getElementById('amount').value = '0.00';
          document.getElementById('amount').disabled = false;
          if (document.getElementById('ajax_surcharge_cell')) {
            document.getElementById('ajax_surcharge_cell').innerHTML = '<FONT SIZE="+1">A credit card surcharge of <% $money_char %>0.00 is included in this payment</FONT>';
          }
        }
        else {
        	document.getElementById('payment_amount_row').style.display = 'block';
        	document.getElementById('invoice_row').style.display = 'none';
          document.getElementById('<% $opt{prefix} %>invoice').value = 'select';
          document.getElementById('amount').value = amount.toFixed(2);
          if (document.getElementById('ajax_surcharge_cell')) {
            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>';
          }
        }

      }

      function <% $opt{prefix} %>invoice_select_changed(what) {

        var surcharge;
        if (document.getElementById('surcharge_percentage') || document.getElementById('surcharge_percentage')) {
          surcharge = (+what.value * +document.getElementById('surcharge_percentage').value) + +document.getElementById('surcharge_flatfee').value;
        }
        else { surcharge = 0; }
        var amount = +what.value + +surcharge;

        if ( what.value == 'select' ) {
          alert("we have select");
        	document.getElementById('payment_amount_row').style.display = 'none';
        	document.getElementById('amount').value = '';
        }
        else {
        	document.getElementById('payment_amount_row').style.display = 'block';
          document.getElementById('amount').value = amount.toFixed(2);
          if (document.getElementById('ajax_surcharge_cell')) {
            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>';
          }
        }

      }

</SCRIPT>

<%init>

my %opt = @_;

my $conf = new FS::Conf;
my $money_char = $conf->config('money_char') || '$';

</%init>