- Модуль: voximplant
- Путь к файлу: ~/bitrix/modules/voximplant/lib/integration/report/handler/periodcompare/periodcompare.php
- Класс: BitrixVoximplantIntegrationReportHandlerPeriodComparePeriodCompare
- Вызов: PeriodCompare::getQueryForReport
public function getQueryForReport(): Query
{
$filterParameters = $this->getFilterParameters();
$startDate = DateTime::createFromUserTime($filterParameters['TIME_PERIOD_from']);
$finishDate = DateTime::createFromUserTime($filterParameters['TIME_PERIOD_to']);
$previousStartDate = DateTime::createFromUserTime($filterParameters['PREVIOUS_TIME_PERIOD_from']);
$previousFinishDate = DateTime::createFromUserTime($filterParameters['PREVIOUS_TIME_PERIOD_to']);
$secondDifference = $this->getDifferenceInSeconds($previousStartDate, $startDate);
$dateDifference = $this->getDateInterval($filterParameters['TIME_PERIOD_datesel'], $secondDifference);
$subQuery = StatisticTable::query();
$this->addDateWithGrouping($subQuery, true);
$subQuery->addSelect('PREVIOUS_DATE');
if ($filterParameters['PORTAL_USER_ID'])
{
$subQuery->addSelect('PORTAL_USER_ID');
}
$this->addToQueryFilterCase($subQuery, $filterParameters);
$this->addCallTypeField($subQuery, $filterParameters['INCOMING'], 'CALL_COUNT');
$subQuery->whereBetween('CALL_START_DATE', $previousStartDate, $previousFinishDate);
$this->addIntervalByDatasel($subQuery, $filterParameters['TIME_PERIOD_datesel'], $dateDifference);
$query = StatisticTable::query();
$this->addDateWithGrouping($query, true);
$query->addSelect('previous.DATE', 'PREVIOUS_DATE');
if ($filterParameters['PORTAL_USER_ID'])
{
$query->addSelect('PORTAL_USER_ID');
}
$this->addToQueryFilterCase($query, $filterParameters);
$this->addCallTypeField($query, $filterParameters['INCOMING'], 'CALL_COUNT',true);
$query->whereBetween('CALL_START_DATE', $startDate, $finishDate);
$query->registerRuntimeField(new ReferenceField(
'previous',
BitrixMainEntityBase::getInstanceByQuery($subQuery),
Join::on('this.DATE', 'ref.PREVIOUS_DATE')
));
$this->addCallTypeCompareField($query, 'CALL_COUNT');
return $query;
}