- Модуль: catalog
- Путь к файлу: ~/bitrix/modules/catalog/lib/component/reportproductlist.php
- Класс: BitrixCatalogComponentReportProductList
- Вызов: ReportProductList::getGridRows
protected function getGridRows(): ?array
{
$productData = $this->getProductData();
if (!$productData)
{
return null;
}
$rows = [];
$this->catalogData = $this->loadCatalog(array_column($productData, 'PRODUCT_ID'));
$formattedFilter = $this->getFormattedFilter();
$receivedQuantityData = $this->getReceivedQuantityData($this->storeId, $formattedFilter);
$outgoingQuantityData = $this->getOutgoingQuantityData($this->storeId, $formattedFilter);
$amountSoldData = $this->getAmountSoldData($this->storeId, $formattedFilter);
$receivedQuantityAmountDifferenceData = [];
$outgoingQuantityAmountDifferenceData = [];
$amountSoldAmountDifferenceData = [];
if (!empty($formattedFilter['REPORT_INTERVAL']))
{
$differenceFilter = $formattedFilter;
$currentTime = new DateTime();
$filterTimeTo = new DateTime($differenceFilter['REPORT_INTERVAL']['TO']);
if ($currentTime > $filterTimeTo)
{
$differenceFilter['REPORT_INTERVAL']['FROM'] = $differenceFilter['REPORT_INTERVAL']['TO'];
$differenceFilter['REPORT_INTERVAL']['TO'] = (new DateTime())->toString();
$receivedQuantityAmountDifferenceData = $this->getReceivedQuantityData($this->storeId, $differenceFilter);
$outgoingQuantityAmountDifferenceData = $this->getOutgoingQuantityData($this->storeId, $differenceFilter);
$amountSoldAmountDifferenceData = $this->getAmountSoldData($this->storeId, $differenceFilter);
}
}
foreach ($productData as $key => $item)
{
$receivedQuantityAmountDifference = (float)($receivedQuantityAmountDifferenceData[$item['PRODUCT_ID']] ?? 0);
$outgoingQuantityAmountDifference = (float)($outgoingQuantityAmountDifferenceData[$item['PRODUCT_ID']] ?? 0);
$amountSoldAmountDifference = (float)($amountSoldAmountDifferenceData[$item['PRODUCT_ID']] ?? 0);
$item['AMOUNT'] =
$item['AMOUNT']
- $receivedQuantityAmountDifference
+ $outgoingQuantityAmountDifference
+ $amountSoldAmountDifference
;
$receivedQuantity = (float)($receivedQuantityData[$item['PRODUCT_ID']] ?? 0);
$outgoingQuantity = (float)($outgoingQuantityData[$item['PRODUCT_ID']] ?? 0);
$amountSold = (float)($amountSoldData[$item['PRODUCT_ID']] ?? 0);
$item['STARTING_QUANTITY'] = (float)$item['AMOUNT'] - $receivedQuantity + $outgoingQuantity + $amountSold;
$item['RECEIVED_QUANTITY'] = (float)($receivedQuantityData[$item['PRODUCT_ID']] ?? 0);
$item['AMOUNT_SOLD'] = (float)($amountSoldData[$item['PRODUCT_ID']] ?? 0);
$item['QUANTITY'] = (float)$item['AMOUNT'] - (float)$item['QUANTITY_RESERVED'];
$rows[] = [
'id' => $item['ID'],
'data' => $item,
'columns' => $this->prepareItemColumn($item),
];
}
return $rows;
}