Option to ignore old CDRs, RT#81480
[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     'cust_main'            => $cust_main,     # custmain needed for selecting invoices
9     'prefix'               => 'pre', # prefix to fields and row ID's
10     'amount'               => 1,     # payment amount optional, if no amount will grab balance due from cust_main
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     'processing_fee' => scalar($conf->config('processing-fee', $cust_main->agentnum)),
26   )
27
28 </%doc>
29
30   <TR ID="payment_option_row">
31     <TH ALIGN="right"><% mt('What would you like to pay') |h %></TH>
32     <TD>
33      <SELECT
34           ID       = "<% $opt{prefix} %>payment_option"
35           NAME     = "<% $opt{prefix} %>payment_option"
36           onChange = "<% $opt{prefix} %>payment_option_changed(this)"
37           <% $opt{disabled} %>
38            >
39       <OPTION VALUE="select">Select the amount you would like to pay</OPTION>
40       <% ($amount > 0) ? '<OPTION VALUE="'.$amount.'">Pay full balance</OPTION>' : '' %>
41       <% (@open_invoices) ? '<OPTION VALUE="invoice">Pay specific invoice</OPTION>' : '' %>
42       <OPTION VALUE="specific">Pay specific amount</OPTION>
43            </SELECT>
44     </TD>
45   </TR>
46
47   <& /elements/tr-select-invoice.html,
48        'cust_main' => $cust_main,
49        'status'    => 'open',
50        'prefix'    => $opt{prefix},
51   &>
52
53   <& /elements/tr-amount_fee.html,
54        'amount'     => $amount,
55        'custnum'    => $custnum,
56        %opt
57   &>
58
59   <SCRIPT TYPE="text/javascript">
60
61       $('#payment_option_row').<% $payment_option_row %>();
62       $('#payment_amount_row').<% $payment_amount_row %>();
63       $('#ajax_processingfee_cell').hide();
64
65       if($('#payment_amount_row').is(':visible')) {
66         var surcharge;
67         var amount = document.getElementById('amount').value;
68
69         if ((document.getElementById('surcharge_percentage') || document.getElementById('surcharge_flatfee')) && amount > 0) {
70           surcharge = (+amount * +document.getElementById('surcharge_percentage').value) + +document.getElementById('surcharge_flatfee').value;
71         }
72         else { surcharge = 0; }
73         if (document.getElementById('ajax_surcharge_cell')) {
74           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>';
75         }
76       }
77
78       function <% $opt{prefix} %>payment_option_changed(what) {
79
80         var surcharge;
81         var processingFee = 0;
82         var pfElement = document.getElementById('processing_fee');
83
84         if (document.getElementById('surcharge_percentage') || document.getElementById('surcharge_flatfee')) {
85           surcharge = (+what.value * +document.getElementById('surcharge_percentage').value) + +document.getElementById('surcharge_flatfee').value;
86         }
87         else { surcharge = 0; }
88
89         if (pfElement != null) {
90           if (pfElement.checked == true) {
91            processingFee = +pfElement.value;
92           }
93         }
94
95         var amount = +what.value + +surcharge + +processingFee;
96         document.getElementById('amount').disabled = true;
97
98         if ( what.value == 'select' ) {
99           $('#payment_amount_row').hide();
100           $('#invoice_row').hide();
101           $("#<% $opt{prefix} %>invoice").val('select');
102           $('#amount').val('');
103         }
104         else if ( what.value == 'invoice' ) {
105           $('#payment_amount_row').hide();
106           $('#invoice_row').show();
107           $('#apply_box_row').hide();
108           $('#apply_box').val('yes');
109           $("#<% $opt{prefix} %>payment_option option[value='select']").remove();
110           var selectExists = ($("#<% $opt{prefix} %>invoice option[value='select']").length > 0);
111           if(!selectExists) {
112             $("#<% $opt{prefix} %>invoice").prepend("<option value='select'>Select an invoice to pay</option>");
113             $("#<% $opt{prefix} %>invoice").val($('option:first', "#<% $opt{prefix} %>invoice").val());
114           }
115           $('#amount').val('');
116         }
117         else if ( what.value == 'specific' ) {
118           $('#payment_amount_row').show();
119           $('#invoice_row').hide();
120           $('#apply_box_row').show();
121           $("#<% $opt{prefix} %>payment_option option[value='select']").remove();
122           $('#amount').val('0.00');
123           document.getElementById('amount').disabled = false;
124           if (document.getElementById('ajax_surcharge_cell')) {
125             document.getElementById('ajax_surcharge_cell').innerHTML = '<FONT SIZE="+1">A credit card surcharge of <% $money_char %>0.00 is included in this payment</FONT>';
126           }
127         }
128         else {
129           $('#payment_amount_row').show();
130           $('#invoice_row').hide();
131           $('#apply_box_row').hide();
132           $('#apply_box').val('yes');
133           $("#<% $opt{prefix} %>payment_option option[value='select']").remove();
134           $('#amount').val(amount.toFixed(2));
135           document.getElementById('amount').disabled = true;
136           if (document.getElementById('ajax_surcharge_cell')) {
137             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>';
138           }
139         }
140
141       }
142
143       function <% $opt{prefix} %>invoice_select_changed(what) {
144
145         var surcharge;
146         var processingFee = 0;
147         var pfElement = document.getElementById('processing_fee');
148         var invdue = document.getElementById("<% $opt{prefix} %>inv" + what.value);
149         if (document.getElementById('surcharge_percentage') || document.getElementById('surcharge_flatfee')) {
150           surcharge = (+invdue.value * +document.getElementById('surcharge_percentage').value) + +document.getElementById('surcharge_flatfee').value;
151         }
152         else { surcharge = 0; }
153
154         if (pfElement != null) {
155           if (pfElement.checked == true) {
156            processingFee = +pfElement.value;
157           }
158         }
159
160         var amount = +invdue.value + +surcharge + +processingFee;
161
162         if ( what.value == 'select' ) {
163           $('#payment_amount_row').hide();
164           $('#amount').val('');
165         }
166         else {
167           $('#payment_amount_row').show();
168           $("#<% $opt{prefix} %>invoice option[value='select']").remove();
169           $('#amount').val(amount.toFixed(2));
170           document.getElementById('amount').disabled = true;
171           if (document.getElementById('ajax_surcharge_cell')) {
172             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>';
173           }
174         }
175
176       }
177
178       function <% $opt{prefix} %>process_fee_changed(what) {
179
180         if (document.getElementById('processing_fee').checked == true) {
181           var amount = +document.getElementById('amount').value + +document.getElementById('processing_fee').value;
182           $('#amount').val(amount.toFixed(2));
183           $('#ajax_processingfee_cell').show();
184         }
185         else {
186           var amount = +document.getElementById('amount').value - +document.getElementById('processing_fee').value;
187           $('#amount').val(amount.toFixed(2));
188           $('#ajax_processingfee_cell').hide();
189         }
190
191       }
192
193 </SCRIPT>
194
195 <%init>
196
197 my %opt = @_;
198
199 my $cust_main = $opt{'cust_main'};
200 my $amount = $opt{'amount'} ? $opt{'amount'} : $cust_main->balance;
201 my $custnum = $cust_main->custnum;
202
203 my @open_invoices = $cust_main->open_cust_bill;
204
205 my $payment_option_row = "show";
206 my $payment_amount_row = "hide";
207
208 unless ($amount > 0 && @open_invoices) {
209   $payment_option_row = "hide";
210   $payment_amount_row = "show";
211 }
212
213 my $conf = new FS::Conf;
214 my $money_char = $conf->config('money_char') || '$';
215
216 </%init>