19 private $sumConfiguration = array();
23 $this->userId = $userId;
24 $this->siteId = $siteId;
29 $this->sumConfiguration = $sumConfiguration;
36 if (!Loader::includeModule(
'currency'))
41 if(empty($this->userId))
46 $filter = $this->createFilterBySumConfiguration($this->sumConfiguration);
47 $orderUserId = $this->userId;
48 $filter = array_merge(array(
49 'USER_ID' => $orderUserId,
50 '=LID' => $this->siteId,
56 foreach (array(self::TYPE_ORDER_NON_ARCHIVED, self::TYPE_ORDER_ARCHIVED) as $orderType)
58 $sum += $this->sumOrders($filter, $orderType);
64 private function createFilterBySumConfiguration($sumConfiguration)
67 if (empty($sumConfiguration))
72 $type = $sumConfiguration[
'type_sum_period'];
73 $periodData = $sumConfiguration[
'sum_period_data'];
75 if ($type === self::TYPE_COUNT_PERIOD_INTERVAL)
77 if (!empty($periodData[
'order_start']))
79 $filter[
'>=DATE_INSERT'] = Main\Type\DateTime::createFromTimestamp($periodData[
'order_start']);
81 if (!empty($periodData[
'order_end']))
83 $filter[
'<DATE_INSERT'] = Main\Type\DateTime::createFromTimestamp($periodData[
'order_end']);
86 elseif ($type === self::TYPE_COUNT_PERIOD_RELATIVE)
88 $value = (int)$periodData[
'period_value'];
89 $typeRelativePeriod = $periodData[
'period_type'];
90 if (!in_array($typeRelativePeriod, array(
'D',
'M',
'Y')))
95 $start =
new Main\Type\DateTime();
96 $end = $start->add(
"-P{$value}{$typeRelativePeriod}");
98 $filter[
'>=DATE_INSERT'] = $end;
100 elseif ($type === self::TYPE_COUNT_PERIOD_ALL_TIME)
108 private function sumOrders($filter, $orderType)
111 if ($orderType === self::TYPE_ORDER_ARCHIVED)
114 $provider =
'\Bitrix\Sale\Archive\Manager';
116 elseif ($orderType === self::TYPE_ORDER_NON_ARCHIVED)
119 $provider =
'\Bitrix\Sale\Order';
122 if ($provider ===
null)
127 $orders = $provider::getList(
130 'select' => array(
'DATE_INSERT',
'PRICE',
'CURRENCY')
136 foreach ($orders as $orderData)
140 $currency = $orderData[
'CURRENCY'];
143 if ($currency !== $orderData[
'CURRENCY'])
145 $sum += \CCurrencyRates::ConvertCurrency($orderData[
'PRICE'], $orderData[
'CURRENCY'], $currency);
149 $sum += $orderData[
'PRICE'];