InvoiceUserInvoicesNumberGenerator::parseTemplate

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. InvoiceUserInvoicesNumberGenerator
  4. parseTemplate
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integration/numerator/invoiceuserinvoicesnumbergenerator.php
  • Класс: Bitrix\Crm\Integration\Numerator\InvoiceUserInvoicesNumberGenerator
  • Вызов: InvoiceUserInvoicesNumberGenerator::parseTemplate
public function parseTemplate($template)
{
	$tableName = $this->getTableName();
	/** @var \Bitrix\Main\Entity\DataManager $tableName */
	$userIdOfOrder = $tableName::query()
		->addSelect('USER_ID')
		->where('ID', $this->orderId)
		->exec()
		->fetch();

	if ($userIdOfOrder)
	{
		$userIdOfOrder = intval($userIdOfOrder['USER_ID']);
		$countOrderOfUser = $tableName::query()
			->addSelect('ORDERS_COUNT')
			->registerRuntimeField(
				new ExpressionField(
					'ORDERS_COUNT',
					'COUNT(ID)'
				)
			)
			->where('USER_ID', $userIdOfOrder)
			->addGroup('USER_ID')
			->exec()
			->fetch();

		if ($countOrderOfUser)
		{
			$numID = (intval($countOrderOfUser["ORDERS_COUNT"]) > 0) ? $countOrderOfUser["ORDERS_COUNT"] : 1;
			$value = $userIdOfOrder . "_" . $numID;
		}
		else
		{
			$value = $userIdOfOrder . "_1";
		}
	}
	else
	{
		$value = '';
	}

	return str_replace($this->getWordToReplace(), $value, $template);
}

Добавить комментарий