• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/history/invoicestatushistoryentry.php
  • Класс: Bitrix\Crm\History\InvoiceStatusHistoryEntry
  • Вызов: InvoiceStatusHistoryEntry::getLatest
static function getLatest($ownerID)
{
	if(!is_int($ownerID))
	{
		$ownerID = (int)$ownerID;
	}

	if($ownerID <= 0)
	{
		throw new Main\ArgumentException('Owner ID must be greater than zero.', 'ownerID');
	}

	$subQuery = new Query(InvoiceStatusHistoryTable::getEntity());
	$subQuery->registerRuntimeField('', new ExpressionField('MAX_ID', 'MAX(ID)'));
	$subQuery->addSelect('MAX_ID');
	$subQuery->addFilter('=OWNER_ID', $ownerID);

	$query = new Query(InvoiceStatusHistoryTable::getEntity());
	$query->addSelect('*');
	$query->registerRuntimeField('',
		new ReferenceField('M',
			Base::getInstanceByQuery($subQuery),
			array('=this.ID' => 'ref.MAX_ID'),
			array('join_type' => 'INNER')
		)
	);

	$dbResult = $query->exec();
	$result = $dbResult->fetch();
	return is_array($result) ? $result : null;
}