11 $value = parent::extractValue($fieldType, $field, $request);
13 if ($value && mb_strpos($value,
'|') !==
false)
15 list($sum, $currency) = explode(
'|', $value);
16 $value = doubleval($sum) .
'|' . $currency;
25 if (mb_strpos($valueA,
'|') ===
false || mb_strpos($valueB,
'|') ===
false)
27 return parent::compareValues($valueA, $valueB);
30 list($sumA, $currencyA) = explode(
'|', $valueA);
31 list($sumB, $currencyB) = explode(
'|', $valueB);
33 $sumA = (double) $sumA;
34 $sumB = (double) $sumB;
38 $currencyA = self::getDefaultCurrencyId();
42 $currencyB = self::getDefaultCurrencyId();
45 if ($currencyA !== $currencyB)
47 $sumB = self::convertMoney($sumB, $currencyB, $currencyA);
50 return parent::compareValues($sumA, $sumB);
55 $formatted = parent::formatValuePrintable($fieldType, $value);
56 $formatted = str_replace(
' ',
' ', $formatted);
61 private static function getDefaultCurrencyId()
65 if($currencyId !==
null)
72 $lang = \CLanguage::GetByID(
'ru');
79 $lang = \CLanguage::GetByID(
'de');
89 private static function normalizeCurrencyID($currencyID)
91 return mb_strtoupper(trim(strval($currencyID)));
94 private static function convertMoney($sum, $srcCurrencyID, $dstCurrencyID, $srcExchRate = -1)
96 $sum = doubleval($sum);
98 if (!Loader::includeModule(
'currency'))
103 $srcCurrencyID = self::normalizeCurrencyID($srcCurrencyID);
104 $dstCurrencyID = self::normalizeCurrencyID($dstCurrencyID);
105 $srcExchRate = doubleval($srcExchRate);
107 if($sum === 0.0 || $srcCurrencyID === $dstCurrencyID)
112 if($srcExchRate <= 0)
114 $result = \CCurrencyRates::ConvertCurrency($sum, $srcCurrencyID, $dstCurrencyID);
118 $result = \CCurrencyRates::ConvertCurrency(
119 doubleval($sum * $srcExchRate),
120 \
Bitrix\Currency\CurrencyManager::getBaseCurrency(),
126 $formatInfo = \CCurrencyLang::GetCurrencyFormat($dstCurrencyID);
127 if(isset($formatInfo[
'DECIMALS']))
129 $decimals = intval($formatInfo[
'DECIMALS']);
132 $result = round($result, $decimals);