Results 1 to 3 of 3

Thread: Formatting Custom Currency in ListView/EditView

  1. #1
    ErikLindquist is offline Sugar Community Member
    Join Date
    Aug 2006
    Posts
    44

    Default Formatting Custom Currency in ListView/EditView

    I found an discussion on formatting custom currencies in the DetailView which allowed a raw value to be read from the database and displayed in the DetailView with the appropriate currency format (2000000 --> 2,000,000). I assume it grabs the format from the system settings. In the ListView and EditView, I get a number in exponential format 2E+06. If I change the data format to Integer I can get rid of the exponent, but I can't get the appropriate number format.


    For the DetailView I inserted the following code after the lines:
    // adding custom fields:
    require_once('modules/DynamicFields/templates/Files/DetailView.php');

    Code:
    //Add following lines
    if($focus->project_cost_c != '') {
        require_once('modules/Currencies/Currency.php');
        $xtpl->assign("PROJECT_COST_C", format_number($focus->project_cost_c));
    }
    However, I can't seem to figure out how to get the appropriate format for the ListView and EditView, The formatting of the data seems to be done somewhere else.

    Could someone please show me where and how to update the format in ListView and EditView.

    Thanks,

    Erik

  2. #2
    ErikLindquist is offline Sugar Community Member
    Join Date
    Aug 2006
    Posts
    44

    Default Re: Formatting Custom Currency in ListView/EditView

    I found that to get the currency format in the EditView including the $ symbol you simply need to set the currency format in the customer lisview def file found in:
    custom\modules\Opportunities\metadata\listviewdefs .php

    Code:
      'PROJECT_COST_C' => 
      array (
        'width' => 10,
        'label' => 'Project_Cost_CAD__c',
     	'align' => 'right',
        'default' => true,
     	'currency_format' => true,
      ),
    But I still have not figured out how to do the same thing in the EditView so that my custom PROJECT_COST_C field has the same format as the AMOUNT field. If I try to key in comma separators for PROJECT_COST_C, Sugar truncates everything after the comma when I go to save the changes, which could have very serious implications if it was not caught. So I need to find a way to allow users to key in numbers with commas the same way you can do it with the Opportunities AMOUNT field.

    Thanks,

    Erik

  3. #3
    mlopez is offline Junior Member
    Join Date
    Dec 2006
    Posts
    1

    Default Re: Formatting Custom Currency in ListView/EditView

    Erik the format_number function needs some extra parameters to indicate whether the currency symbols should be displayed or not. I have done the following:

    Code:
    $currency_settings = array("currency_symbol" => true);
    $formatted_total = format_number($unformatted_total, 2, 2, $currency_settings);
    When calling the format_number the first parameter indicates the unformatted amount being passed to it.
    The second parameter indicates how many positions to the right of the decimal point to round to.
    The third position indicates how many numerical positions there should be to the right of the decimal point
    and the fourth is an array where you can indicate extra parameters and settings.

    You can take a closer look at the function definition by going to /modules/Currencies/Currency.php

    Hope this helps!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •