- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/integration/report/handler/salesdynamics/basegraph.php
- Класс: Bitrix\Crm\Integration\Report\Handler\SalesDynamics\BaseGraph
- Вызов: BaseGraph::getMultipleGroupedData
public function getMultipleGroupedData()
{
$items = [];
$labels = [];
$baseCurrency = \CCrmCurrency::GetAccountCurrencyID();
$calculatedData = $this->getCalculatedData();
$normalizedData = [];
$totalAmount = 0;
foreach ($calculatedData as $value)
{
$closedDate = new Date($value["CLOSED"], static::DATE_INDEX_FORMAT);
$dateIndex = $closedDate->format(static::DATE_INDEX_FORMAT);
if($value["CURRENCY_ID"] == $baseCurrency)
{
$amount = $value["SUM"];
}
else
{
$amount = \CCrmCurrency::ConvertMoney($value["SUM"], $value["CURRENCY_ID"], $baseCurrency);
}
$totalAmount += $amount;
if(isset($normalizedData[$dateIndex]))
{
$normalizedData[$dateIndex]["SUM"] += $amount;
}
else
{
$normalizedData[$dateIndex] = [
"CLOSED" => $closedDate,
"SUM" => $amount
];
}
}
/* $filterParameters = $this->getFilterParameters();
if(isset($filterParameters['TIME_PERIOD']))
{
$minDate = DateTime::createFromUserTime($filterParameters['TIME_PERIOD']['from']);
$maxDate = DateTime::createFromUserTime($filterParameters['TIME_PERIOD']['to']);
}*/
if(count($normalizedData) > 0)
{
$this->padNormalizedData($normalizedData);
}
foreach ($normalizedData as $date => $value)
{
$closedDate = $value["CLOSED"] instanceof Date ? $value["CLOSED"] : new Date($date, static::DATE_INDEX_FORMAT);
$urlParams = [];
if($this->getDateGrouping() === static::GROUP_MONTH)
{
$urlParams['CLOSEDATE_from'] = $closedDate->format(static::DATE_INDEX_FORMAT);
$urlParams['CLOSEDATE_to'] = (clone $closedDate)->add('1m')->format(static::DATE_INDEX_FORMAT);
}
else
{
$urlParams['CLOSEDATE'] = $closedDate->format(static::DATE_INDEX_FORMAT);
}
$item = [
"groupBy" => $date,
"value" => (float)$value["SUM"],
"label" => $this->formatDateForLabel($closedDate),
"balloon" => [
"title" => $this->formatDateForTitle($closedDate),
],
"targetUrl" => $this->getTargetUrl('/crm/deal/analytics/list/', $urlParams)
];
$items[] = $item;
$labels[$date] = $this->formatDateForLabel($closedDate);
}
return [
"items" => $items,
"config" => [
"groupsLabelMap" => $labels,
"reportTitle" => $this->getFormElement("label")->getValue(),
"reportColor" => $this->getFormElement("color")->getValue(),
"reportTitleShort" => $this->getFormElement("label")->getValue(),
"reportTitleMedium" => $this->getFormElement("label")->getValue(),
"amount" => [
"value" => \CCrmCurrency::MoneyToString($totalAmount, $baseCurrency),
],
"dateFormatForLabel" => $this->getDateFormatForLabel(),
"dateGrouping" => $this->getDateGrouping()
]
];
}