CCurrencyLang::disableUseHideZero(); $orderId = (int) $GLOBALS["SALE_INPUT_PARAMS"]["ORDER"]["ID"]; if ($orderId) { /** @var \Bitrix\Sale\Order $order */ $order = \Bitrix\Sale\Order::load($orderId); if ($order) { /** @var \Bitrix\Sale\PaymentCollection $paymentCollection */ $paymentCollection = $order->getPaymentCollection(); if ($paymentCollection) { /** @var \Bitrix\Sale\Payment $payment */ foreach ($paymentCollection as $payment) { if (!$payment->isInner()) { break; } } if ($payment) { $context = \Bitrix\Main\Application::getInstance()->getContext(); $service = \Bitrix\Sale\PaySystem\Manager::getObjectById($payment->getPaymentSystemId()); if ($_REQUEST['pdf'] && $_REQUEST['GET_CONTENT'] == 'Y') { $result = $service->initiatePay($payment, $context->getRequest(), \Bitrix\Sale\PaySystem\BaseServiceHandler::STRING); if ($result->isSuccess()) { return $result->getTemplate(); } } $result = $service->initiatePay($payment, $context->getRequest()); } CCurrencyLang::enableUseHideZero(); } } }
public static function MoneyToString($sum, $currencyID, $formatStr = '') { if (!CModule::IncludeModule('currency')) { return number_format($sum, 2, '.', ''); } $formatInfo = CCurrencyLang::GetCurrencyFormat($currencyID); $formatInfo['DECIMALS'] = isset($formatInfo['DECIMALS']) ? intval($formatInfo['DECIMALS']) : 2; if (!isset($formatInfo['DEC_POINT'])) { $formatInfo['DEC_POINT'] = '.'; } if (!empty($formatInfo['THOUSANDS_VARIANT'])) { $thousands = $formatInfo['THOUSANDS_VARIANT']; if ($thousands === 'N') { $formatInfo['THOUSANDS_SEP'] = ''; } elseif ($thousands === 'D') { $formatInfo['THOUSANDS_SEP'] = '.'; } elseif ($thousands === 'C') { $formatInfo['THOUSANDS_SEP'] = ','; } elseif ($thousands === 'S' || $thousands === 'B') { $formatInfo['THOUSANDS_SEP'] = chr(32); } } if (!isset($formatInfo['THOUSANDS_SEP'])) { $formatInfo['THOUSANDS_SEP'] = ''; } if (is_integer($sum) || is_float($sum)) { // Stansard format for float CCurrencyLang::enableUseHideZero(); return CCurrencyLang::CurrencyFormat($sum, $currencyID, $formatStr !== '#'); } else { // Do not convert to float to avoid data lost caused by overflow (9 999 999 999 999 999.99 ->10 000 000 000 000 000.00) $triadSep = strval($formatInfo['THOUSANDS_SEP']); $decPoint = strval($formatInfo['DEC_POINT']); $dec = intval($formatInfo['DECIMALS']); $sum = str_replace(',', '.', strval($sum)); list($i, $d) = explode('.', $sum, 2); $len = strlen($i); $leadLen = $len % 3; if ($leadLen === 0) { $leadLen = 3; //take a first triad } $lead = substr($i, 0, $leadLen); if (!is_string($lead)) { $lead = ''; } $triads = substr($i, $leadLen); if (!is_string($triads)) { $triads = ''; } $s = $triads !== '' ? $lead . preg_replace('/(\\d{3})/', $triadSep . '\\1', $triads) : ($lead !== '' ? $lead : '0'); $s .= $decPoint . str_pad(substr($d, 0, $dec), $dec, '0', STR_PAD_RIGHT); } if (!empty($formatInfo['THOUSANDS_VARIANT']) && $formatInfo['THOUSANDS_VARIANT'] === 'B') { $s = str_replace(' ', ' ', $s); } $formatStr = strval($formatStr); if ($formatStr === '' && $formatInfo['FORMAT_STRING'] !== '') { $formatStr = $formatInfo['FORMAT_STRING']; } if ($formatStr === '' || $formatStr === '#') { return strip_tags($s); } //Skip HTML entities return strip_tags(preg_replace('/(^|[^&])#/', '${1}' . $s, $formatStr)); }