Use specific function when formatting money for a default
authoreileen <emcnaughton@wikimedia.org>
Wed, 30 Dec 2020 02:00:32 +0000 (15:00 +1300)
committereileen <emcnaughton@wikimedia.org>
Wed, 30 Dec 2020 02:00:32 +0000 (15:00 +1300)
It seems that there are really only 2 ways money::format is called
1) for presenting money - with symbols - in this case only 2 params are passed in
2) for prefilling the form value - in which case some combination of the last 3 are passed in

We have an alternate function that works in the latter case - at which point we could deprecate all
3 in the former case (after a bit more grepping).

The function name is formatLocaleNumericRoundedForDefaultCurrency

I have to admit I'm tempted to remove 'locale' from that name - although
I guess it denotes the swapping of thousand separators

CRM/Contribute/Form/AdditionalPayment.php
CRM/Contribute/Form/Contribution.php
CRM/Grant/Form/Grant.php
CRM/Member/Form.php

index d60f59ccbda63eeb131dbba6970f9413612e2091..52bd3afaf8d0a769bd7414f811ad85c22e4f519a 100644 (file)
@@ -154,7 +154,7 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract
     }
 
     if ($this->isARefund() && $this->amountDue < 0) {
-      $defaults['total_amount'] = CRM_Utils_Money::format(abs($this->amountDue), NULL, NULL, TRUE);
+      $defaults['total_amount'] = CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency(abs($this->amountDue));
     }
     elseif ($this->_owed && $this->amountDue > 0) {
       $defaults['total_amount'] = CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($this->_owed);
index 54c6be460011080c421b992b5f1c985feccd8a47..88d85391bbf46f128f74fcb110d09c9ecf7ddeaf 100644 (file)
@@ -359,11 +359,11 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     // Fix the display of the monetary value, CRM-4038.
     if (isset($defaults['total_amount'])) {
       $total_value = $defaults['total_amount'];
-      $defaults['total_amount'] = CRM_Utils_Money::format($total_value, NULL, '%a');
+      $defaults['total_amount'] = CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($total_value);
       if (!empty($defaults['tax_amount'])) {
         $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
         if (empty($componentDetails['membership']) && empty($componentDetails['participant'])) {
-          $defaults['total_amount'] = CRM_Utils_Money::format($total_value - $defaults['tax_amount'], NULL, '%a');
+          $defaults['total_amount'] = CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($total_value - $defaults['tax_amount']);
         }
       }
     }
index 84125e58d9a39bb9083301c5a38ce3a0bbd9352a..d63b9e565b7d3f96322c71e25919089a6c21cda3 100644 (file)
@@ -107,13 +107,13 @@ class CRM_Grant_Form_Grant extends CRM_Core_Form {
 
       // fix the display of the monetary value, CRM-4038
       if (isset($defaults['amount_total'])) {
-        $defaults['amount_total'] = CRM_Utils_Money::format($defaults['amount_total'], NULL, '%a');
+        $defaults['amount_total'] = CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($defaults['amount_total']);
       }
       if (isset($defaults['amount_requested'])) {
-        $defaults['amount_requested'] = CRM_Utils_Money::format($defaults['amount_requested'], NULL, '%a');
+        $defaults['amount_requested'] = CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($defaults['amount_requested']);
       }
       if (isset($defaults['amount_granted'])) {
-        $defaults['amount_granted'] = CRM_Utils_Money::format($defaults['amount_granted'], NULL, '%a');
+        $defaults['amount_granted'] = CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($defaults['amount_granted']);
       }
     }
     else {
index 07d99d2cd5f250e84bc2506d9d9ec54e5753fa01..292cef47b8d9bab282f584fbf9d5cb4d440ffa3c 100644 (file)
@@ -161,7 +161,7 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment {
       $params = ['id' => $this->_id];
       CRM_Member_BAO_Membership::retrieve($params, $defaults);
       if (isset($defaults['minimum_fee'])) {
-        $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
+        $defaults['minimum_fee'] = CRM_Utils_Money::formatLocaleNumericRoundedForDefaultCurrency($defaults['minimum_fee']);
       }
 
       if (isset($defaults['status'])) {