From 2996649ba54636ab8a791ee21ae1b7616b38bb42 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..e44b0e66e05 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') { + 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..19076457468 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'){ + $value = formatDecimalInConfigSettings($this->module->$attribute, false); + return $value; } return $this->module->$attribute; }