• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integration/report/handler/lead.php
  • Класс: Bitrix\Crm\Integration\Report\Handler\Lead
  • Вызов: Lead::getLeadPassingTime
private function getLeadPassingTime()
{
	$query = new Query(LeadTable::getEntity());
	$query->addSelect(new \Bitrix\Main\Entity\ExpressionField('AVG_SPENT_TIME', 'AVG(%s)', 'FULL_HISTORY.SPENT_TIME'));
	$this->addToQueryFilterCase($query);
	$this->addPermissionsCheck($query);
	$query->whereNot('FULL_HISTORY.STATUS_SEMANTIC_ID', 'S');
	$query->where('FULL_HISTORY.IS_SUPPOSED', 'N');
	//$query->addGroup('FULL_HISTORY.STATUS_ID');

	$results = $query->exec()->fetchAll();

	$successSpentTime = 0;
	if (!$results)
	{
		return $successSpentTime;
	}
	foreach ($results as $result)
	{
		$successSpentTime += $result['AVG_SPENT_TIME'];
	}

	return $successSpentTime;
}