From 9567164874fd27522a630d23b7a54c04c6bb6623 Mon Sep 17 00:00:00 2001 From: SinergiaCRM Date: Wed, 7 Aug 2024 10:50:47 +0000 Subject: [PATCH] Fix #9261 - Use decimal symbol configured in system and user --- include/utils.php | 17 +++++++++++++++++ modules/AOS_PDF_Templates/templateParser.php | 7 +++++++ modules/EmailTemplates/EmailTemplateParser.php | 3 +++ 3 files changed, 27 insertions(+) diff --git a/include/utils.php b/include/utils.php index d6c8362008e..2f9b0ace1b3 100755 --- a/include/utils.php +++ b/include/utils.php @@ -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); +} + diff --git a/modules/AOS_PDF_Templates/templateParser.php b/modules/AOS_PDF_Templates/templateParser.php index 25e93977402..b4b4249461c 100755 --- a/modules/AOS_PDF_Templates/templateParser.php +++ b/modules/AOS_PDF_Templates/templateParser.php @@ -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}; } diff --git a/modules/EmailTemplates/EmailTemplateParser.php b/modules/EmailTemplates/EmailTemplateParser.php index 1bff6b0db6e..91bc464c43e 100644 --- a/modules/EmailTemplates/EmailTemplateParser.php +++ b/modules/EmailTemplates/EmailTemplateParser.php @@ -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; }