Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10596 - No display of user preferences in a decimal type field in PDF templates #10598

Open
wants to merge 1 commit into
base: hotfix
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}