133 $this->catalogData = $this->loadCatalog(array_column($productData,
'PRODUCT_ID'));
140 $receivedQuantityAmountDifferenceData = [];
141 $outgoingQuantityAmountDifferenceData = [];
142 $amountSoldAmountDifferenceData = [];
144 if (!empty($formattedFilter[
'REPORT_INTERVAL']))
146 $differenceFilter = $formattedFilter;
148 $filterTimeTo =
new DateTime($differenceFilter[
'REPORT_INTERVAL'][
'TO']);
149 if ($currentTime > $filterTimeTo)
151 $differenceFilter[
'REPORT_INTERVAL'][
'FROM'] = $differenceFilter[
'REPORT_INTERVAL'][
'TO'];
152 $differenceFilter[
'REPORT_INTERVAL'][
'TO'] = (
new DateTime())->toString();
155 $amountSoldAmountDifferenceData = $this->
getAmountSoldData($this->storeId, $differenceFilter);
159 foreach ($productData as $key => $item)
161 $receivedQuantityAmountDifference = (float)($receivedQuantityAmountDifferenceData[$item[
'PRODUCT_ID']] ?? 0);
162 $outgoingQuantityAmountDifference = (float)($outgoingQuantityAmountDifferenceData[$item[
'PRODUCT_ID']] ?? 0);
163 $amountSoldAmountDifference = (float)($amountSoldAmountDifferenceData[$item[
'PRODUCT_ID']] ?? 0);
166 - $receivedQuantityAmountDifference
167 + $outgoingQuantityAmountDifference
168 + $amountSoldAmountDifference
171 $receivedQuantity = (float)($receivedQuantityData[$item[
'PRODUCT_ID']] ?? 0);
172 $outgoingQuantity = (float)($outgoingQuantityData[$item[
'PRODUCT_ID']] ?? 0);
173 $amountSold = (float)($amountSoldData[$item[
'PRODUCT_ID']] ?? 0);
174 $item[
'STARTING_QUANTITY'] = (float)$item[
'AMOUNT'] - $receivedQuantity + $outgoingQuantity + $amountSold;
175 $item[
'RECEIVED_QUANTITY'] = (float)($receivedQuantityData[$item[
'PRODUCT_ID']] ?? 0);
176 $item[
'AMOUNT_SOLD'] = (float)($amountSoldData[$item[
'PRODUCT_ID']] ?? 0);
177 $item[
'QUANTITY'] = (float)$item[
'AMOUNT'] - (
float)$item[
'QUANTITY_RESERVED'];
190 $navParams = $this->gridOptions->getNavParams();
191 $pageSize = (int)$navParams[
'nPageSize'];
193 $pageNavigation = new \Bitrix\Main\UI\PageNavigation($this->navParamName);
194 $pageNavigation->allowAllRecords(
false)->setPageSize($pageSize)->initFromUri();
198 $pageNavigation->setRecordCount($totalCount);
204 'STUB' => $totalCount <= 0 ? [
'title' => static::getEmptyStub()] :
null,
207 'CURRENT_PAGE' => $pageNavigation->getCurrentPage(),
208 'NAV_OBJECT' => $pageNavigation,
209 'TOTAL_ROWS_COUNT' => $totalCount,
211 'ALLOW_ROWS_SORT' =>
false,
212 'AJAX_OPTION_JUMP' =>
'N',
213 'AJAX_OPTION_STYLE' =>
'N',
214 'AJAX_OPTION_HISTORY' =>
'N',
215 'AJAX_ID' => \CAjax::GetComponentID(
'bitrix:main.ui.grid',
'',
''),
216 'SHOW_PAGINATION' => $totalCount > 0,
217 'SHOW_NAVIGATION_PANEL' =>
true,
218 'SHOW_PAGESIZE' =>
true,
221 [
'NAME' =>
'10',
'VALUE' =>
'10'],
222 [
'NAME' =>
'20',
'VALUE' =>
'20'],
223 [
'NAME' =>
'50',
'VALUE' =>
'50'],
224 [
'NAME' =>
'100',
'VALUE' =>
'100'],
225 [
'NAME' =>
'200',
'VALUE' =>
'200'],
226 [
'NAME' =>
'500',
'VALUE' =>
'500'],
229 'SHOW_ROW_CHECKBOXES' =>
false,
230 'SHOW_CHECK_ALL_CHECKBOXES' =>
false,
231 'SHOW_ACTION_PANEL' =>
false,
232 'SHOW_GRID_SETTINGS_MENU' =>
false,
233 'SHOW_SELECTED_COUNTER' =>
false,
234 'HANDLE_RESPONSE_ERRORS' =>
true,
235 'ALLOW_STICKED_COLUMNS' =>
true,
241 $navParams = $this->gridOptions->getNavParams();
242 $pageSize = (int)$navParams[
'nPageSize'];
243 $gridSort = $this->gridOptions->GetSorting([
'sort' => $this->defaultGridSort]);
245 $pageNavigation = new \Bitrix\Main\UI\PageNavigation($this->navParamName);
246 $pageNavigation->allowAllRecords(
false)->setPageSize($pageSize)->initFromUri();
248 $this->arResult[
'GRID'][
'ROWS'] = [];
250 $offset = $pageNavigation->getOffset();
251 $order = $gridSort[
'sort'];
252 $limit = $pageNavigation->getLimit();
256 return $query->exec()->fetchAll();
275 $baseStoreFilterValues = $filter[
'=STORE_ID'];
276 unset($filter[
'=STORE_ID']);
277 $reportInterval = $filter[
'REPORT_INTERVAL'] ?? [];
278 unset($filter[
'REPORT_INTERVAL']);
280 $storeDocsFilter = [
'=DOCUMENT.STATUS' =>
'Y'];
281 $shipmentsFilter = [
'=ORDER_DELIVERY.DEDUCTED' =>
'Y'];
283 if (!empty($reportInterval))
285 $storeDocsFilter += [
286 '<=DOCUMENT.DATE_STATUS' =>
new DateTime($reportInterval[
'TO']),
288 $shipmentsFilter += [
289 '<=ORDER_DELIVERY.DATE_DEDUCTED' =>
new DateTime($reportInterval[
'TO']),
295 $storeDocsFilter[] = [
297 '=DOCS_ELEMENT.STORE_FROM' =>
$storeId,
298 '=DOCS_ELEMENT.STORE_TO' =>
$storeId,
301 $shipmentsFilter[
'=STORE_BARCODE.STORE_ID'] =
$storeId;
302 $filter[] = [
'=STORE_ID' =>
$storeId];
304 elseif (!empty($baseStoreFilterValues))
306 $storeDocsFilter[] = $baseStoreFilterValues;
307 $shipmentsFilter[
'=STORE_BARCODE.STORE_ID'] = $baseStoreFilterValues;
308 $filter[] = [
'=STORE_ID' => $baseStoreFilterValues];
318 $storeQuery->setSelect([
'ID' ,
'PRODUCT_ID',
'AMOUNT',
'QUANTITY_RESERVED',
'MEASURE_ID' =>
'PRODUCT.MEASURE']);
319 $storeQuery->registerRuntimeField(
322 StoreDocumentElementTable::class,
323 Join::on(
'this.PRODUCT_ID',
'ref.ELEMENT_ID')
326 $storeQuery->registerRuntimeField(
329 StoreDocumentTable::class,
330 Join::on(
'this.DOCS_ELEMENT.DOC_ID',
'ref.ID')
333 $storeQuery->registerRuntimeField(
337 Join::on(
'this.PRODUCT_ID',
'ref.PRODUCT_ID')
340 $storeQuery->registerRuntimeField(
343 ShipmentItemTable::class,
344 Join::on(
'this.BASKET.ID',
'ref.BASKET_ID')
347 $storeQuery->registerRuntimeField(
350 ShipmentItemStoreTable::class,
351 Join::on(
'this.SHIPMENT_ITEM.ID',
'ref.ORDER_DELIVERY_BASKET_ID')
354 $storeQuery->registerRuntimeField(
357 ShipmentTable::class,
358 Join::on(
'this.SHIPMENT_ITEM.ORDER_DELIVERY_ID',
'ref.ID')
362 $storeQuery->setFilter($filter);
363 $storeQuery->setDistinct();
369 $storeQuery->setOrder($order);
373 $storeQuery->setLimit($limit);
377 $storeQuery->setOffset($offset);
380 $storeQuery->countTotal(
true);
386 $allStoreQuery->registerRuntimeField(
'',
389 Base::getInstanceByQuery($storeQuery),
390 [
'this.ID' =>
'ref.PRODUCT_ID'],
391 [
'join_type' =>
'INNER']
395 $allStoreQuery->registerRuntimeField(
403 $allStoreQuery->registerRuntimeField(
407 'SUBQUERY.QUANTITY_RESERVED'
411 $allStoreQuery->setSelect([
413 'PRODUCT_ID' =>
'ID',
416 'MEASURE_ID' =>
'MEASURE',
421 $allStoreQuery->setOrder($order);
426 $allStoreQuery->setLimit($limit);
431 $allStoreQuery->setOffset($offset);
434 $allStoreQuery->countTotal(
true);
436 return $allStoreQuery;