/** * @see SugarFieldBase::importSanitize() */ public function importSanitize($value, $vardef, $focus, ImportFieldSanitize $settings) { require_once 'include/SugarCurrency/SugarCurrency.php'; /** @var Currency $base_currency */ $base_currency = SugarCurrency::getBaseCurrency(); $currency_id = $settings->currency_id; // Remove the grouping separator $value = str_replace($settings->num_grp_sep, '', $value); // change the decimal separator to a . if it's not already one if ($settings->dec_sep != '.') { $value = str_replace($settings->dec_sep, '.', $value); } if (isset($vardef['convertToBase']) && $vardef['convertToBase']) { // convert amount from base $value = str_replace($base_currency->symbol, '', $value); try { $value = SugarCurrency::convertAmountFromBase($value, $settings->currency_id); } catch (SugarMath_Exception $sme) { $GLOBALS['log']->error('Currency Field Import Error: ' . $sme->getMessage()); return false; } } elseif (isset($vardef['is_base_currency']) && $vardef['is_base_currency']) { $value = str_replace($base_currency->symbol, '', $value); $currency_id = $base_currency->id; } else { $value = str_replace($settings->currency_symbol, '', $value); } // last check, if for some reason we get here and the value is not numeric, we should just fail out. if (!is_numeric($value)) { return false; } return SugarCurrency::formatAmount($value, $currency_id, 6, '.', '', false); }
function fill_in_additional_list_fields() { if (isset($this->best_case) && !empty($this->best_case)) { $this->best_case = SugarCurrency::convertAmountFromBase($this->best_case, $this->currency_id); } if (isset($this->worst_case) && !empty($this->worst_case)) { $this->worst_case = SugarCurrency::convertAmountFromBase($this->worst_case, $this->currency_id); } if (isset($this->likely_case) && !empty($this->likely_case)) { $this->likely_case = SugarCurrency::convertAmountFromBase($this->likely_case, $this->currency_id); } }