Merge pull request #2147 from eileenmcnaughton/CRM-13901
[civicrm-core.git] / CRM / Utils / Money.php
index 6ffa9b5c597504bcef1f595780a3b07d80c03e09..456bba09371c4f695eb20f254029a0033e08ddf5 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -49,15 +49,16 @@ class CRM_Utils_Money {
    * %C - the currency ISO code (e.g., 'USD') if provided
    * %c - the currency symbol (e.g., '$') if available
    *
-   * @param float  $amount    the monetary amount to display (1234.56)
-   * @param string $currency  the three-letter ISO currency code ('USD')
-   * @param string $format    the desired currency format
+   * @param float  $amount      the monetary amount to display (1234.56)
+   * @param string $currency    the three-letter ISO currency code ('USD')
+   * @param string $format      the desired currency format
+   * @param string $valueFormat the desired monetary value display format (e.g. '%!i')
    *
    * @return string  formatted monetary string
    *
    * @static
    */
-  static function format($amount, $currency = NULL, $format = NULL, $onlyNumber = FALSE) {
+  static function format($amount, $currency = NULL, $format = NULL, $onlyNumber = FALSE, $valueFormat = NULL) {
 
     if (CRM_Utils_System::isNull($amount)) {
       return '';
@@ -68,11 +69,15 @@ class CRM_Utils_Money {
     if (!$format) {
       $format = $config->moneyformat;
     }
-
+    
+    if (!$valueFormat) {
+      $valueFormat = $config->moneyvalueformat;
+    }
+     
     if ($onlyNumber) {
       // money_format() exists only in certain PHP install (CRM-650)
       if (is_numeric($amount) and function_exists('money_format')) {
-        $amount = money_format($config->moneyvalueformat, $amount);
+        $amount = money_format($valueFormat, $amount);
       }
       return $amount;
     }
@@ -85,16 +90,12 @@ class CRM_Utils_Money {
       $currency = $config->defaultCurrency;
     }
 
-    if (!$format) {
-      $format = $config->moneyformat;
-    }
-
     // money_format() exists only in certain PHP install (CRM-650)
     // setlocale() affects native gettext (CRM-11054, CRM-9976)
     if (is_numeric($amount) && function_exists('money_format')) {
       $lc = setlocale(LC_MONETARY, 0);
       setlocale(LC_MONETARY, 'en_US.utf8', 'en_US', 'en_US.utf8', 'en_US', 'C');
-      $amount = money_format($config->moneyvalueformat, $amount);
+      $amount = money_format($valueFormat, $amount);
       setlocale(LC_MONETARY, $lc);
     }