RT# 34134 - Fixed error with amount not being sent when field disabled.
[freeside.git] / httemplate / elements / tr-select-payment_options.html
index 5197c37..a59963a 100644 (file)
@@ -1,3 +1,30 @@
+<%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>
                <OPTION VALUE="select">Select payment option</OPTION>
                <OPTION VALUE="<% $opt{amount} %>">Pay full balance</OPTION>
                <OPTION VALUE="invoice">Pay specific invoice</OPTION>
-               <OPTION VALUE="">Pay specific amount</OPTION>
+      <OPTION VALUE="specific">Pay specific amount</OPTION>
        </SELECT>       
     </TD>
   </TR>
 
   <& /elements/tr-select-invoice.html,
-       %opt
+       'custnum' => $opt{custnum},
+       'prefix'  => $opt{prefix},
   &>
 
   <& /elements/tr-amount_fee.html,
+       'row_style'  => 'STYLE="display:none;"',
        %opt
   &>
 
 
       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('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('amount').value = what.value;
+          document.getElementById('<% $opt{prefix} %>invoice').value = 'select';
+          document.getElementById('amount').value = amount.toFixed(2);
+          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 %>' + 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 = what.value;
+          document.getElementById('amount').value = amount.toFixed(2);
+          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 %>' + surcharge.toFixed(2) + ' is included in this payment</FONT>';
+          }
         }
 
       }
 
 my %opt = @_;
 
+my $conf = new FS::Conf;
+my $money_char = $conf->config('money_char') || '$';
+
 </%init>
\ No newline at end of file