Skip to content

Commit

Permalink
Hotfix - Plantillas PDF - Formatear número con las preferencias del u…
Browse files Browse the repository at this point in the history
…suario (#429)
  • Loading branch information
ainaraRT authored Nov 19, 2024
1 parent efdea78 commit 2bf44cb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions SticInclude/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public static function createMandate()
}

/**
* Set the proper decimal separator according to the user/system configuration
* Set value with appropriate separators according to user/system configuration
*
* @param Decimal $decimalValue
* @param Boolean $userSetting. Indicates whether to choose user or system configuration
Expand All @@ -494,13 +494,24 @@ public static function formatDecimalInConfigSettings($decimalValue, $userSetting
{
global $current_user, $sugar_config;

// Get the user preferences for the thousands and decimal separator and the number of decimal places
if ($userSetting) {
// User decimal separator
$user_dec_sep = (!empty($current_user->id) ? $current_user->getPreference('dec_sep') : null);
// User thousands separator
$user_grp_sep = (!empty($current_user->id) ? $current_user->getPreference('num_grp_sep') : null);
// User number of decimal places
$user_sig_digits = (!empty($current_user->id) ? $current_user->getPreference('default_currency_significant_digits') : null);
}

// Set the user preferences or the default preferences
$dec_sep = empty($user_dec_sep) ? $sugar_config['default_decimal_seperator'] : $user_dec_sep;
$grp_sep = empty($user_grp_sep) ? $sugar_config['default_number_grouping_seperator'] : $user_grp_sep;
$sig_digits = empty($user_sig_digits) ? $sugar_config['default_currency_significant_digits'] : $user_sig_digits;

return str_replace('.', $dec_sep, $decimalValue);
// Format the number
$value = number_format($decimalValue, $sig_digits, $dec_sep, $grp_sep);
return $value;
}

/**
Expand Down

0 comments on commit 2bf44cb

Please sign in to comment.