CRM-18405: When creating a contribution in the back-end, total amount is incorrect
authordeb.monish <monish.deb@webaccessglobal.com>
Tue, 17 May 2016 12:52:59 +0000 (18:22 +0530)
committerdeb.monish <monish.deb@webaccessglobal.com>
Tue, 17 May 2016 14:26:22 +0000 (19:56 +0530)
templates/CRM/Contribute/Form/Contribution.tpl

index 6c48e96a649fd980e45d3d8dede776e19912dc13..d9dc0c0f267ce7df1d109e1e1db1f51750a4e387 100644 (file)
@@ -608,11 +608,14 @@ function showStartDate( ) {
 }
 
 {/literal}{/if}{literal}
+var thousandMarker = "{/literal}{$config->monetaryThousandSeparator}{literal}";
+var separator = "{/literal}{$config->monetaryDecimalPoint}{literal}";
+
 cj('#fee_amount').change( function() {
-  var totalAmount = cj('#total_amount').val();
-  var feeAmount = cj('#fee_amount').val();
-  var netAmount = totalAmount.replace(/,/g, '') - feeAmount.replace(/,/g, '');
-  if (!cj('#net_amount').val() && totalAmount) {
+  var totalAmount = cj('#total_amount').val().replace(thousandMarker,'').replace(separator,'.');
+  var feeAmount = cj('#fee_amount').val().replace(thousandMarker,'').replace(separator,'.');
+  var netAmount = totalAmount - feeAmount;
+  if (totalAmount) {
     cj('#net_amount').val(CRM.formatMoney(netAmount, true));
   }
 });
@@ -650,16 +653,14 @@ CRM.$(function($) {
           cj("#totalTaxAmount").show( );
         }
         var totalAmount = $('#total_amount').val();
-        var thousandMarker = '{/literal}{$config->monetaryThousandSeparator}{literal}';
-        var seperator = '{/literal}{$config->monetaryDecimalPoint}{literal}';
-        // replace all thousandMarker and change the seperator to a dot
-  totalAmount = totalAmount.replace(thousandMarker,'').replace(seperator,'.');
+        // replace all thousandMarker and change the separator to a dot
+        totalAmount = totalAmount.replace(thousandMarker,'').replace(separator,'.');
 
         var totalTaxAmount = '{/literal}{$totalTaxAmount}{literal}';
         var taxAmount = (taxRate/100)*totalAmount;
         taxAmount = isNaN (taxAmount) ? 0:taxAmount;
         var totalTaxAmount = taxAmount + Number(totalAmount);
-        totalTaxAmount = formatMoney( totalTaxAmount, 2, seperator, thousandMarker );
+        totalTaxAmount = formatMoney( totalTaxAmount, 2, separator, thousandMarker );
 
         $("#totalTaxAmount" ).html('Amount with tax : <span id="currencySymbolShow">' + currencySymbol + '</span> '+ totalTaxAmount);
       }