Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#1019 Calculate.tpl: fix the Total Amount currency formatting. #16487

Merged
merged 2 commits into from
Feb 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions templates/CRM/Price/Form/Calculate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -154,33 +154,27 @@ function calculateTotalFee() {
* Display calculated amount.
*/
function display(totalfee) {
// totalfee is monetary, round it to 2 decimal points so it can
// go as a float - CRM-13491
totalfee = Math.round(totalfee*100)/100;
var totalFormattedFee = CRM.formatMoney(totalfee);
cj('#pricevalue').html(totalFormattedFee);

// totalfee is monetary, round it to 2 decimal points so it can
// go as a float - CRM-13491
totalfee = Math.round(totalfee*100)/100;
var totalEventFee = formatMoney( totalfee, 2, separator, thousandMarker);
document.getElementById('pricevalue').innerHTML = "<b>"+symbol+"</b> "+totalEventFee;
cj('#total_amount').val( totalfee );
cj('#pricevalue').data('raw-total', totalfee).trigger('change');

cj('#total_amount').val( totalfee );
cj('#pricevalue').data('raw-total', totalfee).trigger('change');

( totalfee < 0 ) ? cj('table#pricelabel').addClass('disabled') : cj('table#pricelabel').removeClass('disabled');
if (typeof skipPaymentMethod == 'function') {
// Advice to anyone who, like me, feels hatred towards this if construct ... if you remove the if you
// get an error on participant 2 of a event that requires approval & permits multiple registrants.
skipPaymentMethod();
}
}
if (totalfee < 0) {
cj('table#pricelabel').addClass('disabled');
}
else {
cj('table#pricelabel').removeClass('disabled');
}

//money formatting/localization
function formatMoney (amount, c, d, t) {
var n = amount,
c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "," : d,
t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
if (typeof skipPaymentMethod == 'function') {
// Advice to anyone who, like me, feels hatred towards this if construct ... if you remove the if you
// get an error on participant 2 of a event that requires approval & permits multiple registrants.
skipPaymentMethod();
}
}

{/literal}
Expand Down