CRM-16239 total amount (money) format on backend membership form
authorsunil <esunil.pawar@gmail.com>
Mon, 6 Apr 2015 08:15:04 +0000 (13:45 +0530)
committersunil <esunil.pawar@gmail.com>
Mon, 6 Apr 2015 08:15:04 +0000 (13:45 +0530)
js/Common.js
templates/CRM/Member/Form/Membership.tpl
templates/CRM/Member/Form/MembershipRenewal.tpl

index 1b08d777f7072a47f6f42b9dbe3f17d0d191f0ff..97ff46d0b4f70e8d1a356a2a18367d9cc4eec44d 100644 (file)
@@ -1337,13 +1337,14 @@ CRM.strings = CRM.strings || {};
    * @return string
    */
   var currencyTemplate;
-  CRM.formatMoney = function(value, format) {
+  CRM.formatMoney = function(value, format, onlyNumber) {
     var decimal, separator, sign, i, j, result;
     if (value === 'init' && format) {
       currencyTemplate = format;
       return;
     }
     format = format || currencyTemplate;
+    onlyNumber = onlyNumber || false;
     result = /1(.?)234(.?)56/.exec(format);
     if (result === null) {
       return 'Invalid format passed to CRM.formatMoney';
@@ -1355,6 +1356,9 @@ CRM.strings = CRM.strings || {};
     i = parseInt(value = Math.abs(value).toFixed(2)) + '';
     j = ((j = i.length) > 3) ? j % 3 : 0;
     result = sign + (j ? i.substr(0, j) + separator : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + separator) + (2 ? decimal + Math.abs(value - i).toFixed(2).slice(2) : '');
+    if ( onlyNumber ) {
+      return result;
+    }
     return format.replace(/1.*234.*56/, result);
   };
 
index 4610f6578fa21224b079158746e863cb925fe3a3..2e302a260a7a0e521640fdd295dcde751d62b7e7 100644 (file)
           else {
       var feeTotal = Number((taxRate/100) * (allMemberships[memType]['total_amount_numeric'] * term))+Number(allMemberships[memType]['total_amount_numeric'] * term );
           }
-          cj("#total_amount").val( feeTotal.toFixed(2) );
+          cj("#total_amount").val(CRM.formatMoney(feeTotal, '', true));
         }
         else {
     if (taxRate) {
             var feeTotal = parseFloat(Number((taxRate/100) * allMemberships[memType]['total_amount'])+Number(allMemberships[memType]['total_amount_numeric'])).toFixed(2);
-      cj("#total_amount").val( feeTotal );
+      cj("#total_amount").val(CRM.formatMoney(feeTotal, '', true));
           }
           else {
       var feeTotal = allMemberships[memType]['total_amount'];
index b97a5d2f94e088281f4a00909c2702b5c13ee421..43555d7f484dc6e03851986e61c9b638f6e805c3 100644 (file)
       var term = cj("#num_terms").val();
       if (term) {
         var renewTotal = allMemberships[memType]['total_amount_numeric'] * term;
-        cj("#total_amount").val(renewTotal.toFixed(2));
+        cj("#total_amount").val(CRM.formatMoney(renewTotal, '', true));
       }
       else {
         cj("#total_amount").val(allMemberships[memType]['total_amount']);