- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/integration/numerator/quotenumbergenerator.php
- Класс: Bitrix\Crm\Integration\Numerator\QuoteNumberGenerator
- Вызов: QuoteNumberGenerator::parseTemplate
public function parseTemplate($template)
{
global $DB;
$dbres = $DB->Query("SELECT USER_ID FROM b_sale_order WHERE ID = '" . $this->orderId . "'", true);
$value = '';
if ($arRes = $dbres->GetNext())
{
$userID = $arRes["USER_ID"];
switch (strtolower($DB->type))
{
case "mysql":
$strSql = "SELECT MAX(CAST(SUBSTRING(ACCOUNT_NUMBER, LENGTH('" . $userID . "_') + 1) as UNSIGNED)) as NUM_ID FROM b_sale_order WHERE ACCOUNT_NUMBER LIKE '" . $userID . "\_%'";
break;
case "oracle":
$strSql = "SELECT MAX(CAST(SUBSTR(ACCOUNT_NUMBER, LENGTH('" . $userID . "_') + 1) as NUMBER)) as NUM_ID FROM b_sale_order WHERE ACCOUNT_NUMBER LIKE '" . $userID . "_%'";
break;
case "mssql":
$strSql = "SELECT MAX(CAST(SUBSTRING(ACCOUNT_NUMBER, LEN('" . $userID . "_') + 1, LEN(ACCOUNT_NUMBER)) as INT)) as NUM_ID FROM b_sale_order WHERE ACCOUNT_NUMBER LIKE '" . $userID . "_%'";
break;
}
$dbres = $DB->Query($strSql, true);
if ($arRes = $dbres->GetNext())
{
$numID = (intval($arRes["NUM_ID"]) > 0) ? $arRes["NUM_ID"] + 1 : 1;
$value = $userID . "_" . $numID;
}
else
{
$value = $userID . "_1";
}
}
$template = str_replace(self::getPatternFor(self::TEMPLATE_WORD_USER_ID_QUOTE_ID), $value, $template);
return $template;
}