From: sunil Date: Mon, 6 Apr 2015 08:15:04 +0000 (+0530) Subject: CRM-16239 total amount (money) format on backend membership form X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=567e9eea3066f39e6705e2ca2f8c3181c96db3e5;p=civicrm-core.git CRM-16239 total amount (money) format on backend membership form --- diff --git a/js/Common.js b/js/Common.js index 1b08d777f7..97ff46d0b4 100644 --- a/js/Common.js +++ b/js/Common.js @@ -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); }; diff --git a/templates/CRM/Member/Form/Membership.tpl b/templates/CRM/Member/Form/Membership.tpl index 4610f6578f..2e302a260a 100644 --- a/templates/CRM/Member/Form/Membership.tpl +++ b/templates/CRM/Member/Form/Membership.tpl @@ -397,12 +397,12 @@ 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']; diff --git a/templates/CRM/Member/Form/MembershipRenewal.tpl b/templates/CRM/Member/Form/MembershipRenewal.tpl index b97a5d2f94..43555d7f48 100644 --- a/templates/CRM/Member/Form/MembershipRenewal.tpl +++ b/templates/CRM/Member/Form/MembershipRenewal.tpl @@ -384,7 +384,7 @@ 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']);