Skip to content

Commit

Permalink
Fix salesagility#10596 - No display of user preferences in a decimal …
Browse files Browse the repository at this point in the history
…type field in PDF templates
  • Loading branch information
SinergiaCRM committed Dec 10, 2024
1 parent e572230 commit d7eb0b5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions include/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6343,18 +6343,32 @@ function isWebToLeadAllowedRedirectHost(string $url): bool {
}

/**
* 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
* @return Decimal
*/
function formatDecimalInConfigSettings($decimalValue, $userSetting = false) {
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;
return str_replace('.', $dec_sep, $decimalValue);
$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;

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

0 comments on commit d7eb0b5

Please sign in to comment.