Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-12700

Allow monetary value (not amount) format override

    Details

    • Type: Improvement
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.3.3
    • Fix Version/s: 4.4.0
    • Component/s: CiviContribute
    • Labels:
      None

      Description

      In using the contribute widget I found myself wanting to override the default monetary value format to NOT show the cents. The widget is a macro kind of look at the campaign and the cents make the widget too cluttered.

      I went into the widget and found the portion that formats the values:

      Widget = modules/civicrm/CRM/Contribute/BAO/Widget.php

      Makes a call to the Money.php utility to format the values:
      $data['money_target_display'] = CRM_Utils_Money::format($data['money_target']);

      Taking a look at the actual money util I see that there is an opportunity to override the amount format but not the value format.

      =========================
      /**

      • format a monetary string
        *
      • Format a monetary string basing on the amount provided,
      • ISO currency code provided and a format string consisting of:
        *
      • %a - the formatted amount
      • %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
        *
      • @return string formatted monetary string
        *
      • @static
        */
        static function format($amount, $currency = NULL, $format = NULL, $onlyNumber = FALSE) {

      ===============

      I propose to add a fifth argument allowing override of the value format. Setting a default value of NULL will make it so that existing calls are not broken.

      Adding the fifth v_format along with the following quick change:
      =========
      if (!$v_format)

      { <-- New $v_format = $config->moneyvalueformat; <-- New }

      <-- New

      // 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($v_format, $amount); <-- Change setlocale(LC_MONETARY, $lc); }

      =========

      With this change, I can now make a widget change to force the cents off the widget without changing the entire site default.

        Attachments

          Activity

            People

            • Assignee:
              dgg David Greenberg
              Reporter:
              heneryh Joe Flynn
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1 day
                1d
                Remaining:
                Remaining Estimate - 1 day
                1d
                Logged:
                Time Spent - Not Specified
                Not Specified