RT# 34134 - fixed error with credit surchage not attached to total
authorChristopher Burger <burgerc@freeside.biz>
Mon, 14 May 2018 14:21:15 +0000 (10:21 -0400)
committerChristopher Burger <burgerc@freeside.biz>
Mon, 14 May 2018 14:21:15 +0000 (10:21 -0400)
httemplate/elements/tr-amount_fee.html
httemplate/elements/tr-select-payment_options.html

index 9e6d9e9..3ad2cdf 100644 (file)
@@ -8,7 +8,7 @@
                                 VALUE    = "<% $amount %>"
                                 SIZE     = 8
                                 STYLE    = "text-align:right;"
                                 VALUE    = "<% $amount %>"
                                 SIZE     = 8
                                 STYLE    = "text-align:right;"
-%                               if ( $fee ) {
+%                               if ( $fee || $surcharge ) {
                                   onChange   = "amount_changed(this)"
                                   onKeyDown  = "amount_changed(this)"
                                   onKeyUp    = "amount_changed(this)"
                                   onChange   = "amount_changed(this)"
                                   onKeyDown  = "amount_changed(this)"
                                   onKeyUp    = "amount_changed(this)"
            <FONT SIZE="+1"><% length($amount) ? $money_char. sprintf('%.2f', ($fee_display eq 'add') ? $amount + $fee : $amount - $fee ) : '' %> <% $fee_display eq 'add' ? 'TOTAL' : 'AVAILABLE' %></FONT>
   
 %        }
            <FONT SIZE="+1"><% length($amount) ? $money_char. sprintf('%.2f', ($fee_display eq 'add') ? $amount + $fee : $amount - $fee ) : '' %> <% $fee_display eq 'add' ? 'TOTAL' : 'AVAILABLE' %></FONT>
   
 %        }
+%        if ( $surcharge ) {
+           <INPUT TYPE="hidden" NAME="surcharge_percentage" ID="surcharge_percentage" VALUE="<% $surcharge_percentage %>">
+           <INPUT TYPE="hidden" NAME="surcharge_flatfee" ID="surcharge_flatfee" VALUE="<% $surcharge_flatfee %>">
+      </TD><TD ID="ajax_surcharge_cell" BGCOLOR="#dddddd" STYLE="border:1px solid blue">
+           <FONT SIZE="+1">A credit card surcharge of <% $money_char. sprintf('%.2f', ($amount * $surcharge_percentage) + $surcharge_flatfee) %> is included in this payment</FONT>
+%        }
       </TD></TR></TABLE>
     </TD>
   </TR>
 
       </TD></TR></TABLE>
     </TD>
   </TR>
 
-% if ( $fee ) {
+% if ($fee || $surcharge) {
 
     <SCRIPT TYPE="text/javascript">
 
       function amount_changed(what) {
 
 
     <SCRIPT TYPE="text/javascript">
 
       function amount_changed(what) {
 
-
+% if ( $fee ) {
         var total = '';
         if ( what.value.length ) {
           total = parseFloat(what.value) <% $fee_op %> <% $fee %>;
         var total = '';
         if ( what.value.length ) {
           total = parseFloat(what.value) <% $fee_op %> <% $fee %>;
 
         var total_cell = document.getElementById('ajax_total_cell');
         total_cell.innerHTML = '<FONT SIZE="+1">' + total + ' <% $fee_display eq 'add' ? 'TOTAL' : 'AVAILABLE' %></FONT>';
 
         var total_cell = document.getElementById('ajax_total_cell');
         total_cell.innerHTML = '<FONT SIZE="+1">' + total + ' <% $fee_display eq 'add' ? 'TOTAL' : 'AVAILABLE' %></FONT>';
+% }
+
+% if ( $surcharge ) {
+        var surcharge_cell = document.getElementById('ajax_surcharge_cell');
+        var surcharge = ((what.value - <% $surcharge_flatfee %>) * <% $surcharge_percentage %>) + <% $surcharge_flatfee %>;
+        surcharge_cell.innerHTML = '<FONT SIZE="+1">A credit card surcharge of ' + surcharge.toFixed(2) + ' is included in this payment</FONT>';
+% }
 
       }
 
 
       }
 
@@ -66,6 +79,9 @@ my $fee = '';
 my $fee_pkg = '';
 my $fee_display = '';
 my $fee_op = '';
 my $fee_pkg = '';
 my $fee_display = '';
 my $fee_op = '';
+my $surcharge = '';
+my $surcharge_percentage = 0;
+my $surcharge_flatfee = 0;
 
 if ( $opt{'process-pkgpart'}
      and ! $opt{'process-skip_first'} || $opt{'num_payments'}
 
 if ( $opt{'process-pkgpart'}
      and ! $opt{'process-skip_first'} || $opt{'num_payments'}
@@ -91,11 +107,13 @@ if ( $amount > 0 ) {
     if $fee && $fee_display eq 'subtract';
 
   #&{ $opt{post_fee_callback} }( \$amount ) if $opt{post_fee_callback};
     if $fee && $fee_display eq 'subtract';
 
   #&{ $opt{post_fee_callback} }( \$amount ) if $opt{post_fee_callback};
-  $amount += $amount * $opt{'surcharge_percentage'}/100
-    if $opt{'surcharge_percentage'} > 0;
 
 
-  $amount += $opt{'surcharge_flatfee'}
-    if $opt{'surcharge_flatfee'} > 0;
+  $surcharge_percentage = $opt{'surcharge_percentage'}/100 if $opt{'surcharge_percentage'} > 0;
+  $surcharge_flatfee = $opt{'surcharge_flatfee'} if $opt{'surcharge_flatfee'} > 0;
+  $surcharge = $amount * $surcharge_percentage if $surcharge_percentage > 0;
+  $surcharge += $surcharge_flatfee if $surcharge_flatfee > 0;
+
+  $amount += $surcharge;
 
   $amount = sprintf("%.2f", $amount);
 }
 
   $amount = sprintf("%.2f", $amount);
 }
index 8859b9b..15f9277 100644 (file)
@@ -38,7 +38,7 @@ Example:
                <OPTION VALUE="select">Select payment option</OPTION>
                <OPTION VALUE="<% $opt{amount} %>">Pay full balance</OPTION>
                <OPTION VALUE="invoice">Pay specific invoice</OPTION>
                <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>
        </SELECT>       
     </TD>
   </TR>
@@ -57,6 +57,14 @@ Example:
 
       function <% $opt{prefix} %>payment_option_changed(what) {
 
 
       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';
         if ( what.value == 'select' ) {
                document.getElementById('payment_amount_row').style.display = 'none';
                document.getElementById('invoice_row').style.display = 'none';
@@ -68,24 +76,48 @@ Example:
                document.getElementById('invoice_row').style.display = 'block';
                document.getElementById('amount').value = '';
         }
                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';
         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 = what.value;
+          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) {
 
         }
 
       }
 
       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' ) {
         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('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);
+          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>';
+          }
         }
 
       }
         }
 
       }
@@ -96,4 +128,7 @@ Example:
 
 my %opt = @_;
 
 
 my %opt = @_;
 
+my $conf = new FS::Conf;
+my $money_char = $conf->config('money_char') || '$';
+
 </%init>
\ No newline at end of file
 </%init>
\ No newline at end of file