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))
25 'processing_fee' => scalar($conf->config('processing-fee', $cust_main->agentnum)),
30 <TR ID="payment_option_row">
31 <TH ALIGN="right"><% mt('What would you like to pay') |h %></TH>
34 ID = "<% $opt{prefix} %>payment_option"
35 NAME = "<% $opt{prefix} %>payment_option"
36 onChange = "<% $opt{prefix} %>payment_option_changed(this)"
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>
47 <& /elements/tr-select-invoice.html,
48 'cust_main' => $cust_main,
50 'prefix' => $opt{prefix},
53 <& /elements/tr-amount_fee.html,
55 'custnum' => $custnum,
59 <SCRIPT TYPE="text/javascript">
61 $('#payment_option_row').<% $payment_option_row %>();
62 $('#payment_amount_row').<% $payment_amount_row %>();
63 $('#ajax_processingfee_cell').show();
65 if($('#payment_amount_row').is(':visible')) {
67 var amount = document.getElementById('amount').value;
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;
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>';
78 function <% $opt{prefix} %>payment_option_changed(what) {
81 var processingFee = 0;
82 var pfElement = document.getElementById('processing_fee');
84 if (document.getElementById('surcharge_percentage') || document.getElementById('surcharge_flatfee')) {
85 surcharge = (+what.value * +document.getElementById('surcharge_percentage').value) + +document.getElementById('surcharge_flatfee').value;
87 else { surcharge = 0; }
89 if (pfElement != null) {
90 if (pfElement.checked == true) {
91 processingFee = +pfElement.value;
95 var amount = +what.value + +surcharge + +processingFee;
96 document.getElementById('amount').disabled = true;
98 if ( what.value == 'select' ) {
99 $('#payment_amount_row').hide();
100 $('#invoice_row').hide();
101 $("#<% $opt{prefix} %>invoice").val('select');
102 $('#amount').val('');
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);
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());
115 $('#amount').val('');
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>';
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>';
143 function <% $opt{prefix} %>invoice_select_changed(what) {
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;
152 else { surcharge = 0; }
154 if (pfElement != null) {
155 if (pfElement.checked == true) {
156 processingFee = +pfElement.value;
160 var amount = +invdue.value + +surcharge + +processingFee;
162 if ( what.value == 'select' ) {
163 $('#payment_amount_row').hide();
164 $('#amount').val('');
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>';
178 function <% $opt{prefix} %>process_fee_changed(what) {
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();
186 var amount = +document.getElementById('amount').value - +document.getElementById('processing_fee').value;
187 $('#amount').val(amount.toFixed(2));
188 $('#ajax_processingfee_cell').hide();
199 my $cust_main = $opt{'cust_main'};
200 my $amount = $opt{'amount'} ? $opt{'amount'} : $cust_main->balance;
201 my $custnum = $cust_main->custnum;
203 my @open_invoices = $cust_main->open_cust_bill;
205 my $payment_option_row = "show";
206 my $payment_amount_row = "hide";
208 unless ($amount > 0 && @open_invoices) {
209 $payment_option_row = "hide";
210 $payment_amount_row = "show";
213 my $conf = new FS::Conf;
214 my $money_char = $conf->config('money_char') || '$';