5 include( '/elements/tr-select-payment_options.html',
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' =>
17 ? scalar($conf->config('credit-card-surcharge-percentage', $cust_main->agentnum))
20 'surcharge_flatfee' =>
22 ? scalar($conf->config('credit-card-surcharge-flatfee', $cust_main->agentnum))
29 <TR ID="payment_option_row">
30 <TH ALIGN="right"><% mt('What would you like to pay') |h %></TH>
33 ID = "<% $opt{prefix} %>payment_option"
34 NAME = "<% $opt{prefix} %>payment_option"
35 onChange = "<% $opt{prefix} %>payment_option_changed(this)"
38 <OPTION VALUE="select">Select the amount you would like to pay</OPTION>
39 <% ($amount > 0) ? '<OPTION VALUE="'.$amount.'">Pay full balance</OPTION>' : '' %>
40 <% (@open_invoices) ? '<OPTION VALUE="invoice">Pay specific invoice</OPTION>' : '' %>
41 <OPTION VALUE="specific">Pay specific amount</OPTION>
46 <& /elements/tr-select-invoice.html,
47 'cust_main' => $cust_main,
49 'prefix' => $opt{prefix},
52 <& /elements/tr-amount_fee.html,
54 'custnum' => $custnum,
58 <SCRIPT TYPE="text/javascript">
60 $('#payment_option_row').<% $payment_option_row %>();
61 $('#payment_amount_row').<% $payment_amount_row %>();
63 if($('#payment_amount_row').is(':visible')) {
65 var amount = document.getElementById('amount').value;
67 if ((document.getElementById('surcharge_percentage') || document.getElementById('surcharge_flatfee')) && amount > 0) {
68 surcharge = (+amount * +document.getElementById('surcharge_percentage').value) + +document.getElementById('surcharge_flatfee').value;
70 else { surcharge = 0; }
71 if (document.getElementById('ajax_surcharge_cell')) {
72 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>';
76 function <% $opt{prefix} %>payment_option_changed(what) {
79 if (document.getElementById('surcharge_percentage') || document.getElementById('surcharge_flatfee')) {
80 surcharge = (+what.value * +document.getElementById('surcharge_percentage').value) + +document.getElementById('surcharge_flatfee').value;
82 else { surcharge = 0; }
83 var amount = +what.value + +surcharge;
84 document.getElementById('amount').disabled = true;
86 if ( what.value == 'select' ) {
87 $('#payment_amount_row').hide();
88 $('#invoice_row').hide();
89 $("#<% $opt{prefix} %>invoice").val('select');
92 else if ( what.value == 'invoice' ) {
93 $('#payment_amount_row').hide();
94 $('#invoice_row').show();
95 $('#apply_box_row').hide();
96 $('#apply_box').val('yes');
97 $("#<% $opt{prefix} %>payment_option option[value='select']").remove();
98 var selectExists = ($("#<% $opt{prefix} %>invoice option[value='select']").length > 0);
100 $("#<% $opt{prefix} %>invoice").prepend("<option value='select'>Select an invoice to pay</option>");
101 $("#<% $opt{prefix} %>invoice").val($('option:first', "#<% $opt{prefix} %>invoice").val());
103 $('#amount').val('');
105 else if ( what.value == 'specific' ) {
106 $('#payment_amount_row').show();
107 $('#invoice_row').hide();
108 $('#apply_box_row').show();
109 $("#<% $opt{prefix} %>payment_option option[value='select']").remove();
110 $('#amount').val('0.00');
111 document.getElementById('amount').disabled = false;
112 if (document.getElementById('ajax_surcharge_cell')) {
113 document.getElementById('ajax_surcharge_cell').innerHTML = '<FONT SIZE="+1">A credit card surcharge of <% $money_char %>0.00 is included in this payment</FONT>';
117 $('#payment_amount_row').show();
118 $('#invoice_row').hide();
119 $('#apply_box_row').hide();
120 $('#apply_box').val('yes');
121 $("#<% $opt{prefix} %>payment_option option[value='select']").remove();
122 $('#amount').val(amount.toFixed(2));
123 document.getElementById('amount').disabled = true;
124 if (document.getElementById('ajax_surcharge_cell')) {
125 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>';
131 function <% $opt{prefix} %>invoice_select_changed(what) {
134 var invdue = document.getElementById("<% $opt{prefix} %>inv" + what.value);
135 if (document.getElementById('surcharge_percentage') || document.getElementById('surcharge_flatfee')) {
136 surcharge = (+invdue.value * +document.getElementById('surcharge_percentage').value) + +document.getElementById('surcharge_flatfee').value;
138 else { surcharge = 0; }
139 var amount = +invdue.value + +surcharge;
141 if ( what.value == 'select' ) {
142 $('#payment_amount_row').hide();
143 $('#amount').val('');
146 $('#payment_amount_row').show();
147 $("#<% $opt{prefix} %>invoice option[value='select']").remove();
148 $('#amount').val(amount.toFixed(2));
149 document.getElementById('amount').disabled = true;
150 if (document.getElementById('ajax_surcharge_cell')) {
151 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>';
163 my $cust_main = $opt{'cust_main'};
164 my $amount = $opt{'amount'} ? $opt{'amount'} : $cust_main->balance;
165 my $custnum = $cust_main->custnum;
167 my @open_invoices = $cust_main->open_cust_bill;
169 my $payment_option_row = "show";
170 my $payment_amount_row = "hide";
172 unless ($amount > 0 && @open_invoices) {
173 $payment_option_row = "hide";
174 $payment_amount_row = "show";
177 my $conf = new FS::Conf;
178 my $money_char = $conf->config('money_char') || '$';