Skip to content

Commit

Permalink
dev/translation#48 Implement Brick/Money to better handle currecny va…
Browse files Browse the repository at this point in the history
…lues
  • Loading branch information
seamuslee001 committed Jun 14, 2020
1 parent 9c6d953 commit 87eeca1
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 5 deletions.
6 changes: 4 additions & 2 deletions CRM/Utils/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

use Brick\Money\Money;

/**
* Money utilties
*/
Expand Down Expand Up @@ -135,8 +137,8 @@ public static function getCurrencyPrecision($currency = NULL) {
*/
public static function subtractCurrencies($leftOp, $rightOp, $currency) {
if (is_numeric($leftOp) && is_numeric($rightOp)) {
$precision = pow(10, self::getCurrencyPrecision($currency));
return (($leftOp * $precision) - ($rightOp * $precision)) / $precision;
$money = Money::of($leftOp, $currency);
return $money->minus($rightOp)->getAmount()->toFloat();
}
}

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@
"league/csv": "^9.2",
"tplaner/when": "~3.0.0",
"xkerman/restricted-unserialize": "~1.1",
"typo3/phar-stream-wrapper": "^2 || ^3.0"
"typo3/phar-stream-wrapper": "^2 || ^3.0",
"brick/money": "~0.4",
"ext-intl": "*"
},
"scripts": {
"post-install-cmd": [
Expand Down
97 changes: 95 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 87eeca1

Please sign in to comment.