How to know the currency of a field?

Hi everyone,

I need to access the currency type (ISO 4217) of a currency field because I need to print it in a pdf. I'm using the pdf manager to get the values of the fields from the actual record. Is there a way to get the currency type from the pdf manager?

Parents
  • There is no easy way...

    There is only one currency per record, its id is in currency_id

    The PDF amounts are formatted using the currency symbol rather than the currency's ISO4217

    It would be really nice if there was a choice on which to use in the PDFs.

    The only way I can think of to do what you need is to add a custom field to your module to hold that value, then include it in your PDF using smarty to format the amount without a symbol.

    So your before_save logic hook will have something like:

     

    if ($bean->currency_id == '-99'){
        $bean->reporting_currency_c = 'USD';
    }else{
        $currencyBean = BeanFactory::retrieveBean('Currencies', $bean->currency_id);
        $bean->reporting_currency_c = $currencyBean->iso4217;
    }

    Note that your default currency has ID -99, for us that's USD

    Hope this helps,
    FrancescaS

  • I believe there is a better solution.

    You can create a varchar field "iso4217" in the target module and setup the following sugarLogic formula:

    ifElse(equal($currency_id, "-99"), "USD", related($currencies, "iso4217"))

    Unfortunately you can not configure such formula through Studio because SugarLogic engine doesn't "see" the field "currency_id", so you will need to place it directaly in the field's extended vardefs.

    Finaly you run QRR and it is done.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
Reply
  • I believe there is a better solution.

    You can create a varchar field "iso4217" in the target module and setup the following sugarLogic formula:

    ifElse(equal($currency_id, "-99"), "USD", related($currencies, "iso4217"))

    Unfortunately you can not configure such formula through Studio because SugarLogic engine doesn't "see" the field "currency_id", so you will need to place it directaly in the field's extended vardefs.

    Finaly you run QRR and it is done.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
Children
  • André Lopes,

    your comment made me wonder if we could translate that sugar logic formula into a smarty formula. Unfortunately currencies is not available from the PDF so {if $fields.currency_id== "-99"}USD{else}{$currencies.iso4217}{/if}

    won't work.

    It could be made available by modifying the PDF Manager (overkill?)

    to include the related currencies so they can be referenced directly in the PDF without having to add a field to the module itself.

    How to customize the Sugar PDF Manager 

    But, in theory, one could hard code the currency iso4217 directly in PDF:

    {if $fields.currency_id== "-99"}USD{elseif $fields.currency_id== "<the id of GBP in your system>"}GBP{elseif ...   {/if}

    Not very clean and system dependent, but nonetheless an option.

    All this begs the question.... Angel Magana, can one create custom Smarty Modifiers for Sugar in an upgrade safe manner? If so we should be able to create our own version of

    include/SugarSmarty/plugins/function.sugar_currency_format.php to use the currency iso4217 instead of the symbol

    FrancescaS