• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/internals/accountnumber.php
  • Класс: BitrixSaleInternalsAccountNumberGenerator
  • Вызов: AccountNumberGenerator::generate
static function generate(CollectableEntity $item)
{
	$accountNumber = null;
	/** @var EntityCollection $collection */
	if (!$collection = $item->getCollection())
	{
		throw new MainObjectNotFoundException('Entity "Collection" not found');
	}

	if (!method_exists($collection, "getOrder"))
	{
		throw new MainNotSupportedException();
	}

	/** @var SaleOrderBase $order */
	if (!$order = $collection->getOrder())
	{
		throw new MainObjectNotFoundException('Entity "Order" not found');
	}

	$accountNumber = $order->getField('ACCOUNT_NUMBER').static::ACCOUNT_NUMBER_SEPARATOR;

	$count = 1;
	/** @var CollectableEntity $itemCollection */
	foreach ($collection as $itemCollection)
	{
		if (strval($itemCollection->getField("ACCOUNT_NUMBER")) != "")
		{
			$accountNumberIdList = explode(static::ACCOUNT_NUMBER_SEPARATOR, $itemCollection->getField("ACCOUNT_NUMBER"));

			$itemAccountNumber = trim(end($accountNumberIdList));

			if ($count <= $itemAccountNumber)
				$count = $itemAccountNumber + 1;
		}
	}

	return $accountNumber.$count;
}