- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/integration/report/handler/deal.php
- Класс: Bitrix\Crm\Integration\Report\Handler\Deal
- Вызов: Deal::getDealAmountCountAndSum
private function getDealAmountCountAndSum()
{
$filterParameters = $this->getFilterParameters();
$query = new Query(DealTable::getEntity());
$query->addSelect(new ExpressionField('DISTINCT_OWNER_ID', 'DISTINCT %s', 'FULL_HISTORY.OWNER_ID'));
$query->addSelect('OPPORTUNITY_ACCOUNT');
$query->addSelect('ACCOUNT_CURRENCY_ID', 'CURRENCY');
$this->addToQueryFilterCase($query, $filterParameters);
$this->addTimePeriodToQuery($query, $filterParameters['TIME_PERIOD']);
$this->addPermissionsCheck($query);
$connection = Application::getConnection();
$querySql = 'SELECT SUM(res.OPPORTUNITY_ACCOUNT) as SUM, COUNT(res.DISTINCT_OWNER_ID) COUNT, res.CURRENCY as CURRENCY FROM(';
$querySql .= $query->getQuery();
$querySql .= ') as res';
$queryWithResult = $connection->query($querySql);
$result = $queryWithResult->fetchAll();
return !empty($result[0])
? $result[0]
: [
'COUNT' => 0,
'SUM' => 0,
'CURRENCY' => \CCrmCurrency::GetAccountCurrencyID()
];
}