InvoiceSumStatistics::prepareEntityListFilter

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. InvoiceSumStatistics
  4. prepareEntityListFilter
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/widget/data/leadidle.php
  • Класс: Bitrix\Crm\Widget\Data\LeadIdle
  • Вызов: LeadIdle::prepareEntityListFilter
public function prepareEntityListFilter(array $filterParams)
{
	$filter = self::internalizeFilter($filterParams);
	$query = new Query(LeadStatusHistoryTable::getEntity());
	$query->addSelect('OWNER_ID');
	$query->addGroup('OWNER_ID');

	$period = $filter->getPeriod();
	$periodStartDate = $period['START'];
	$periodEndDate = $period['END'];

	$query->addFilter('=TYPE_ID', HistoryEntryType::CREATION);
	$query->addFilter('>=CREATED_DATE', $periodStartDate);
	$query->addFilter('<=CREATED_DATE', $periodEndDate);

	$query->registerRuntimeField('',
		new ExpressionField(
			'E1',
			'(CASE WHEN NOT EXISTS('.self::prepareHistoryQuery($periodStartDate, $periodEndDate, HistoryEntryType::MODIFICATION, '%s', '_i')->getQuery().') THEN 1 ELSE 0 END)',
			'OWNER_ID'
		)
	);
	$query->addFilter('=E1', 1);

	$query->registerRuntimeField('',
		new ExpressionField(
			'E2',
			'(CASE WHEN NOT EXISTS('.self::prepareHistoryQuery($periodStartDate, $periodEndDate, HistoryEntryType::FINALIZATION, '%s', '_i')->getQuery().') THEN 1 ELSE 0 END)',
			'OWNER_ID'
		)
	);
	$query->addFilter('=E2', 1);

	$query->registerRuntimeField('',
		new ExpressionField(
			'E3',
			'(CASE WHEN NOT EXISTS('.self::prepareActivityQuery($periodStartDate, $periodEndDate, '%s')->getQuery().') THEN 1 ELSE 0 END)',
			'OWNER_ID'
		)
	);
	$query->addFilter('=E3', 1);

	$responsibleIDs = $filter->getResponsibleIDs();
	if(!empty($responsibleIDs))
	{
		$query->addFilter('@RESPONSIBLE_ID', $responsibleIDs);
	}

	return array(
		'__JOINS' => array(
				array(
					'TYPE' => 'INNER',
					'SQL' => 'INNER JOIN('.$query->getQuery().') LI ON LI.OWNER_ID = L.ID'
				)
			)
	);
}

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