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

SearchKit - Respect currency when formatting monetary fields #24524

Merged
merged 3 commits into from
Sep 16, 2022

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Sep 15, 2022

Overview

This fixes SearchKit to correctly format a monetary amount when it's different than the site default currency.
Fixes: https://lab.civicrm.org/dev/core/-/issues/3428

Before

All amounts were shown in the site default (e.g. USD) instead of the correct currency.
image

After

image

Technical Details

This supports entities who have their own currency column. This excludes line_item I've fixed LineItem so it now works by pulling in a join from the associated Contribution record to look up the currency.

@civibot
Copy link

civibot bot commented Sep 15, 2022

(Standard links)

@@ -773,7 +774,8 @@ protected function formatViewValue($key, $rawValue) {
break;

case 'Money':
$formatted = \CRM_Utils_Money::format($rawValue);
$currencyField = $this->getCurrencyField($key);
$formatted = \CRM_Utils_Money::format($rawValue, $data[$currencyField] ?? NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should switch this to \Civi::format()->money()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok @eileenmcnaughton I've made that change - it altered the formatting but all improvements I think... I've updated the screenshot. Adding CA in front of the canadian dollar sign is a good touch. I'm not sure why it removed the trailing .00 from Japanese currency but seems fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Japanese currency has trailing bits....

@eileenmcnaughton eileenmcnaughton merged commit 06d92d3 into civicrm:master Sep 16, 2022
@eileenmcnaughton eileenmcnaughton deleted the currency branch September 16, 2022 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants