44 $storeTotals = $this->getStoreProductData();
45 if (!empty($storeTotals))
47 $receivedQuantities = $this->getReceivedQuantity();
48 $soldAmounts = $this->getSoldAmounts();
49 $outgoingQuantities = $this->getOutgoingQuantity();
50 $receivedQuantitiesDifference = $this->getReceivedQuantityForDifference();
51 $outgoingQuantitiesDifference = $this->getOutgoingQuantityForDifference();
52 $soldAmountsDifference = $this->getSoldAmountsForDifference();
54 $groupedStoreTotals = [];
55 foreach ($storeTotals as $key => $storeTotal)
57 $storeId = (int)$storeTotal[
'TMP_STORE_ID'];
58 $measureId = (int)$storeTotal[
'MEASURE_ID'] ?: \CCatalogMeasure::getDefaultMeasure(
true)[
'ID'];
59 if (isset($groupedStoreTotals[$storeId][$measureId]))
61 $groupedStoreTotals[$storeId][$measureId][
'AMOUNT_SUM'] += (float)$storeTotal[
'AMOUNT_SUM'];
62 $groupedStoreTotals[$storeId][$measureId][
'QUANTITY_RESERVED_SUM'] += (float)$storeTotal[
'QUANTITY_RESERVED_SUM'];
67 $groupedStoreTotals[$storeId][$measureId] = [
68 'TITLE' => $storeTotal[
'TITLE'],
69 'TMP_STORE_ID' => $storeId,
70 'SORT' => $storeTotal[
'SORT'],
71 'AMOUNT_SUM' => (float)$storeTotal[
'AMOUNT_SUM'],
72 'QUANTITY_RESERVED_SUM' => (
float)$storeTotal[
'QUANTITY_RESERVED_SUM'],
73 'MEASURE_ID' => $measureId,
76 if (array_key_exists($storeId, $receivedQuantities))
78 $groupedStoreTotals[$storeId][$measureId][
'RECEIVED_QUANTITIES'] = $receivedQuantities[$storeId];
80 if (array_key_exists($storeId, $receivedQuantitiesDifference))
82 $groupedStoreTotals[$storeId][$measureId][
'RECEIVED_QUANTITIES_DIFFERENCE'] = $receivedQuantitiesDifference[$storeId];
85 if (array_key_exists($storeId, $outgoingQuantities))
87 $groupedStoreTotals[$storeId][$measureId][
'OUTGOING_QUANTITIES'] = $outgoingQuantities[$storeId];
89 if (array_key_exists($storeId, $outgoingQuantitiesDifference))
91 $groupedStoreTotals[$storeId][$measureId][
'OUTGOING_QUANTITIES_DIFFERENCE'] = $outgoingQuantitiesDifference[$storeId];
94 if (array_key_exists($storeId, $soldAmounts))
96 $groupedStoreTotals[$storeId][$measureId][
'SOLD_AMOUNTS'] = $soldAmounts[$storeId];
98 if (array_key_exists($storeId, $soldAmountsDifference))
100 $groupedStoreTotals[$storeId][$measureId][
'SOLD_AMOUNTS_DIFFERENCE'] = $soldAmountsDifference[$storeId];
103 ksort($groupedStoreTotals[$storeId]);
105 ksort($groupedStoreTotals);
107 $storeTotals = $this->prepareStoreTotals($groupedStoreTotals);
115 $sliderUrl = \CComponentEngine::makeComponentPath($componentName);
116 $sliderUrl = getLocalPath(
'components'.$sliderUrl.
'/slider.php');
118 $uri =
new Uri($sliderUrl);
120 if (isset($filter[
'STORES']))
122 $uri->addParams([
'storeIds' => $filter[
'STORES']]);
124 if (isset($filter[
'PRODUCTS']))
126 $uri->addParams([
'productIds' => $filter[
'PRODUCTS']]);
128 if (isset($filter[
'REPORT_INTERVAL']))
131 'reportFrom' => $filter[
'REPORT_INTERVAL'][
'FROM'],
132 'reportTo' => $filter[
'REPORT_INTERVAL'][
'TO'],
139 'reportFrom' => $defaultInterval[
'FROM'],
140 'reportTo' => $defaultInterval[
'TO'],
144 return $uri->getUri();
147 private function getStoreProductData(): array
149 $accessController = AccessController::getCurrent();
150 if (!$accessController->check(ActionDictionary::ACTION_STORE_VIEW))
160 'TITLE' =>
'STORE_TMP.TITLE',
161 'TMP_STORE_ID' =>
'STORE_TMP.ID',
162 'SORT' =>
'STORE_TMP.SORT',
164 'QUANTITY_RESERVED_SUM',
165 'MEASURE_ID' =>
'PRODUCT.MEASURE',
168 '=STORE_TMP.ACTIVE' =>
'Y',
170 'group' => [
'TMP_STORE_ID',
'MEASURE_ID'],
174 new ExpressionField(
'QUANTITY_RESERVED_SUM',
'SUM(%s)', [
'QUANTITY_RESERVED']),
178 Join::on(
'this.STORE_ID',
'ref.ID')
179 ))->configureJoinType(Join::TYPE_RIGHT),
185 if (isset($userFilterParameters[
'STORES']) && is_array($userFilterParameters[
'STORES']))
187 $storesList = $userFilterParameters[
'STORES'];
194 $filteredStoresList = self::getFilteredByRightsStoreList($storesList);
196 if (is_array($filteredStoresList))
198 $queryParams[
'filter'][
'=TMP_STORE_ID'] = $filteredStoresList;
201 if (!empty($userFilterParameters[
'PRODUCTS']) && is_array($userFilterParameters[
'PRODUCTS']))
203 $queryParams[
'filter'][] = $this->
getProductFilter($userFilterParameters[
'PRODUCTS']);
212 '=PRODUCT_ID' => StoreStockFilter::prepareProductFilter($productFilter),
216 '!=QUANTITY_RESERVED' => 0,
221 private function prepareStoreTotals(array $storeTotals): array
223 $preparedTotals = [];
225 foreach ($storeTotals as $storeId => $storeTotal)
227 foreach ($storeTotal as $measureId => $entry)
229 if (!isset($preparedTotals[$storeId]))
231 $preparedTotals[$storeId] = [
232 'TITLE' => $entry[
'TITLE'],
233 'STORE_ID' => $storeId,
238 $soldAmountDifferenceData = $entry[
'SOLD_AMOUNTS_DIFFERENCE'] ?? [];
239 $receivedQuantitiesDifferenceData = $entry[
'RECEIVED_QUANTITIES_DIFFERENCE'] ?? [];
240 $outgoingQuantitiesDifferenceData = $entry[
'OUTGOING_QUANTITIES_DIFFERENCE'] ?? [];
242 (float)$entry[
'AMOUNT_SUM']
243 - ($receivedQuantitiesDifferenceData[$measureId] ?? 0.0)
244 + ($outgoingQuantitiesDifferenceData[$measureId] ?? 0.0)
245 + ($soldAmountDifferenceData[$measureId] ?? 0.0)
247 $quantityReservedSum = (float)$entry[
'QUANTITY_RESERVED_SUM'];
249 $quantity = $amountSum - $quantityReservedSum;
250 $productsSoldAmount = $entry[
'SOLD_AMOUNTS'] ?? [];
251 $receivedQuantityData = $entry[
'RECEIVED_QUANTITIES'] ?? [];
252 $outgoingQuantityData = $entry[
'OUTGOING_QUANTITIES'] ?? [];
256 - ($receivedQuantityData[$measureId] ?? 0.0)
257 + ($outgoingQuantityData[$measureId] ?? 0.0)
258 + ($productsSoldAmount[$measureId] ?? 0.0)
260 $receivedQuantity = ($receivedQuantityData[$measureId] ?? 0.0);
261 $amountSold = $productsSoldAmount[$measureId] ?? 0.0;
263 $isStoreEmpty =
true;
265 $startingQuantity, $receivedQuantity, $amountSum, $quantityReservedSum, $quantity, $amountSold,
267 foreach ($values as $value)
271 $isStoreEmpty =
false;
280 if (!isset($preparedTotals[$storeId][
'TOTALS'][$measureId]))
282 $preparedTotals[$storeId][
'TOTALS'][$measureId] = [
283 'STARTING_QUANTITY' => 0,
284 'RECEIVED_QUANTITY' => 0,
286 'QUANTITY_RESERVED_SUM' => 0,
292 $preparedTotals[$storeId][
'TOTALS'][$measureId][
'STARTING_QUANTITY'] += $startingQuantity;
293 $preparedTotals[$storeId][
'TOTALS'][$measureId][
'RECEIVED_QUANTITY'] += $receivedQuantity;
294 $preparedTotals[$storeId][
'TOTALS'][$measureId][
'AMOUNT_SUM'] += $amountSum;
295 $preparedTotals[$storeId][
'TOTALS'][$measureId][
'QUANTITY_RESERVED_SUM'] += $quantityReservedSum;
296 $preparedTotals[$storeId][
'TOTALS'][$measureId][
'QUANTITY'] += $quantity;
297 $preparedTotals[$storeId][
'TOTALS'][$measureId][
'AMOUNT_SOLD'] += $amountSold;
301 return $preparedTotals;
304 private function getFormattedFilterForDifference(): ?array
307 $differenceFilter = $formattedFilter;
308 $currentTime =
new DateTime();
309 $filterTimeTo =
new DateTime($differenceFilter[
'REPORT_INTERVAL'][
'TO']);
310 if ($currentTime > $filterTimeTo)
312 $differenceFilter[
'REPORT_INTERVAL'][
'FROM'] = $differenceFilter[
'REPORT_INTERVAL'][
'TO'];
313 \CTimeZone::Disable();
314 $differenceFilter[
'REPORT_INTERVAL'][
'TO'] = $currentTime->toString();
315 \CTimeZone::Enable();
322 return $differenceFilter;
325 private function getReceivedQuantityForDifference(): array
327 $formattedFilterForDifference = $this->getFormattedFilterForDifference();
328 if (!$formattedFilterForDifference)
336 private function getOutgoingQuantityForDifference(): array
338 $formattedFilterForDifference = $this->getFormattedFilterForDifference();
339 if (!$formattedFilterForDifference)
347 private function getSoldAmountsForDifference(): array
349 $formattedFilterForDifference = $this->getFormattedFilterForDifference();
350 if (!$formattedFilterForDifference)
358 private function getReceivedQuantity(): array
365 private function getOutgoingQuantity(): array
372 private function getSoldAmounts(): array
386 $formattedFilter = [];
388 $storesList = (isset($filter[
'STORES']) && is_array($filter[
'STORES'])) ? $filter[
'STORES'] :
null;
389 $filteredStoresList = self::getFilteredByRightsStoreList($storesList);
391 if (is_array($filteredStoresList))
393 $formattedFilter[
'STORES'] = $filteredStoresList;
396 if (!empty($filter[
'PRODUCTS']))
398 $formattedFilter[
'PRODUCTS'] = StoreStockFilter::prepareProductFilter($filter[
'PRODUCTS']);
403 !empty($filter[
'REPORT_INTERVAL_from'])
404 && !empty($filter[
'REPORT_INTERVAL_to'])
407 $formattedFilter[
'REPORT_INTERVAL'] = [
408 'FROM' => $filter[
'REPORT_INTERVAL_from'],
409 'TO' => $filter[
'REPORT_INTERVAL_to'],
412 return $formattedFilter;
415 private function getDefaultMeasure(): int
417 static $defaultMeasure = 0;
419 if (empty($defaultMeasure))
421 $fetchedMeasure = \CCatalogMeasure::getList([], [
'=IS_DEFAULT' =>
'Y'])->Fetch();
424 $defaultMeasure = (int)$fetchedMeasure[
'ID'];
432 return $defaultMeasure;
439 foreach ($storeTotals as $storeTotalEntry)
441 foreach ($storeTotalEntry[
'TOTALS'] as $measureId => $total)
443 $startingQuantitySum = (float)$total[
'STARTING_QUANTITY'];
444 $amountSum = (float)$total[
'AMOUNT_SUM'];
445 $receivedQuantity = (float)$total[
'RECEIVED_QUANTITY'];
446 $quantityReservedSum = (float)$total[
'QUANTITY_RESERVED_SUM'];
447 $amountSoldSum = (float)$total[
'AMOUNT_SOLD'];
449 if (!isset($overallTotals[$measureId]))
451 $overallTotals[$measureId] = [
452 'STARTING_QUANTITY' => 0,
453 'RECEIVED_QUANTITY' => 0,
455 'QUANTITY_RESERVED_SUM' => 0,
460 $overallTotals[$measureId][
'STARTING_QUANTITY'] += $startingQuantitySum;
461 $overallTotals[$measureId][
'RECEIVED_QUANTITY'] += $receivedQuantity;
462 $overallTotals[$measureId][
'AMOUNT_SUM'] += $amountSum;
463 $overallTotals[$measureId][
'QUANTITY_RESERVED_SUM'] += $quantityReservedSum;
464 $overallTotals[$measureId][
'QUANTITY'] += $amountSum - $quantityReservedSum;
465 $overallTotals[$measureId][
'AMOUNT_SOLD'] += $amountSoldSum;
469 return $overallTotals;
475 $boardProvider->addFilter(
'boardKey', $key);
477 return $boardProvider->execute()->getFirstResult();
492 $filter = $board->getFilter();
496 $filter =
new Filter($boardKey);
504 static $filterParameters = [];
507 $filterId = $filter->getFilterParameters()[
'FILTER_ID'];
509 if (!$filterParameters[$filterId])
511 $options =
new Options($filterId, $filter::getPresetsList());
512 $fieldList = $filter::getFieldsList();
513 $filterParameters[$filterId] = $options->getFilter($fieldList);
516 return $filterParameters[$filterId];
522 'title' =>
Loc::getMessage(
'BASE_HANDLER_EMPTY_PERMITTED_STORES_LIST_STUB_TITLE'),
523 'description' =>
Loc::getMessage(
'BASE_HANDLER_EMPTY_PERMITTED_STORES_LIST_STUB_DESCRIPTION'),
531 private static function getFilteredByRightsStoreList(?array $inputStoreList =
null): ?array
533 $accessController = AccessController::getCurrent();
535 if (!$accessController->check(ActionDictionary::ACTION_STORE_VIEW))
540 if (!$accessController->checkCompleteRight(ActionDictionary::ACTION_STORE_VIEW))
542 $availableStores = $accessController->getPermissionValue(ActionDictionary::ACTION_STORE_VIEW) ?? [];
544 if (is_array($inputStoreList))
546 return array_values(array_intersect($availableStores, $inputStoreList));
549 return $availableStores;
552 return $inputStoreList;
static getMessage($code, $replace=null, $language=null)