Skip to content

Commit

Permalink
Fix #9261 - Use decimal symbol configured in system and user
Browse files Browse the repository at this point in the history
  • Loading branch information
SinergiaCRM committed Aug 14, 2024
1 parent 80ee82d commit 9567164
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6339,3 +6339,20 @@ function isWebToLeadAllowedRedirectHost(string $url): bool {

return false;
}

/**
* Set the proper decimal separator according to the 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;
if ($userSetting) {
$user_dec_sep = (!empty($current_user->id) ? $current_user->getPreference('dec_sep') : null);
}
$dec_sep = empty($user_dec_sep) ? $sugar_config['default_decimal_seperator'] : $user_dec_sep;
return str_replace('.', $dec_sep, $decimalValue);
}

7 changes: 7 additions & 0 deletions modules/AOS_PDF_Templates/templateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ public static function parse_template_bean($string, $key, &$focus)
ENT_COMPAT, 'UTF-8');
$repl_arr[$key . "_" . $fieldName] = html_entity_decode((string) $focus->{$fieldName},
ENT_COMPAT, 'UTF-8');
} elseif ($field_def['type'] == 'decimal' || $field_def['type'] == 'float') {
if ($_REQUEST['entryPoint'] == 'formLetter') {
$value = formatDecimalInConfigSettings($focus->$fieldName, true);
} else {
$value = formatDecimalInConfigSettings($focus->$fieldName, false);
}
$repl_arr[$key . "_" . $fieldName] = $value;
} else {
$repl_arr[$key . "_" . $fieldName] = $focus->{$fieldName};
}
Expand Down
3 changes: 3 additions & 0 deletions modules/EmailTemplates/EmailTemplateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ private function getValueFromBean($variable)
if (isset($app_list_strings[$enum][$this->module->$attribute])) {
$this->module->$attribute = $app_list_strings[$enum][$this->module->$attribute];
}
} else if (($this->module->field_name_map[$attribute]['type']) && (($this->module->field_name_map[$attribute]['type']) === 'decimal' || ($this->module->field_name_map[$attribute]['type']) === 'float')) {
$value = formatDecimalInConfigSettings($this->module->$attribute, false);
return $value;
}
return $this->module->$attribute;
}
Expand Down

0 comments on commit 9567164

Please sign in to comment.