• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/statistics/dealsumstatisticentry.php
  • Класс: Bitrix\Crm\Statistics\DealSumStatisticEntry
  • Вызов: DealSumStatisticEntry::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(DealSumStatisticsTable::getEntity());
	$subQuery->registerRuntimeField('', new ExpressionField('MAX_CREATED_DATE', 'MAX(CREATED_DATE)'));
	$subQuery->addSelect('MAX_CREATED_DATE');
	$subQuery->addFilter('=OWNER_ID', $ownerID);
	$subQuery->addGroup('OWNER_ID');

	$query = new Query(DealSumStatisticsTable::getEntity());
	$query->addSelect('*');
	$query->registerRuntimeField('',
		new ReferenceField('M',
			Base::getInstanceByQuery($subQuery),
			array('=this.OWNER_ID' => new SqlExpression($ownerID), '=this.CREATED_DATE' => 'ref.MAX_CREATED_DATE'),
			array('join_type' => 'INNER')
		)
	);

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