Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
base.php
1<?php
3
4use Bitrix\Catalog\EO_StoreBatchDocumentElement;
12use Bitrix\Main\Entity\ReferenceField;
16
22abstract class Base
23{
26
27 protected array $storeConditions = [];
28
30 {
31 $this->balancer = $balancer;
32
33 $this->elementBatchTree = $this->buildInventoryTree();
34 }
35
36 abstract public function fill(): Result;
37
38 protected function buildInventoryTree(): ?InventoryTree
39 {
40 $registryUnchanged = $this->loadConductedDocumentElements();
41
42 if (empty($registryUnchanged))
43 {
44 return null;
45 }
46
48
49 foreach ($registryUnchanged as $item)
50 {
51 if (!empty($item['STORE_TO']))
52 {
53 $batchElement = new EO_StoreBatchDocumentElement();
54 $batchElement->setAmount($item['AMOUNT']);
55 $batchElement->setShipmentItemStoreId($item['STORE_TO']);
56 $batchElement->setDocumentElementId($item['ID']);
57 $batchElement->setBatchPrice($item['PURCHASING_PRICE']);
58 $batchElement->setBatchCurrency($item['CURRENCY']);
59
60 $elementBatchTree->append(new Entity\ElementBatchItem($batchElement, $item['STORE_TO']));
61 }
62
63 if (!empty($item['STORE_FROM']))
64 {
65 $batchElement = new EO_StoreBatchDocumentElement();
66 $batchElement->setAmount(-$item['AMOUNT']);
67 $batchElement->setShipmentItemStoreId($item['STORE_TO']);
68 if ($item['DOCUMENT_TYPE'] === StoreDocumentTable::TYPE_SALES_ORDERS)
69 {
70 $batchElement->setShipmentItemStoreId($item['ID']);
71 }
72 else
73 {
74 $batchElement->setDocumentElementId($item['ID']);
75 }
76
77 $elementBatchTree->append(new Entity\ElementBatchItem($batchElement, $item['STORE_FROM']));
78 }
79 }
80
81 return $elementBatchTree;
82 }
83
84 private function loadConductedDocumentElements(): array
85 {
86 $filterDocs = [
87 'ELEMENT_ID' => $this->balancer->getProductId(),
88 '=DOCUMENT.STATUS' => 'Y',
89 ];
90
91 if ($this->balancer->getStartDate() !== null)
92 {
93 $filterDocs['>=STATUS_DATE'] = $this->balancer->getStartDate();
94 }
95
97 'filter' => $filterDocs,
98 'select' => [
99 'ID',
100 'STORE_FROM',
101 'STORE_TO',
102 'PURCHASING_PRICE',
103 'AMOUNT',
104 'DOCUMENT_TYPE' => 'DOCUMENT.DOC_TYPE',
105 'CURRENCY' => 'DOCUMENT.CURRENCY',
106 'DATE' => 'DOCUMENT.DATE_STATUS',
107 'BATCH_ID' => 'BATCH_BINDING.PRODUCT_BATCH_ID',
108 ],
109 'runtime' => [
110 new ReferenceField(
111 'BATCH_BINDING',
113 array('=this.ID' => 'ref.DOCUMENT_ELEMENT_ID'),
114 array('join_type' => 'left'),
115 ),
116 ],
117 'order' => ['DATE' => 'ASC'],
118 ])
119 ->fetchAll()
120 ;
121
122 if (Loader::includeModule('sale'))
123 {
124 $filterSales = [
125 '=ORDER_DELIVERY_BASKET.BASKET.PRODUCT_ID' => $this->balancer->getProductId(),
126 '=ORDER_DELIVERY_BASKET.DELIVERY.DEDUCTED' => 'Y',
127 ];
128
129 if ($this->balancer->getStartDate() !== null)
130 {
131 $filterSales['>=ORDER_DELIVERY_BASKET.DELIVERY.DATE_DEDUCTED'] = $this->balancer->getStartDate();
132 }
133
134 $salesElements = ShipmentItemStoreTable::getList([
135 'filter' => $filterSales,
136 'select' => [
137 'ID',
138 'STORE_FROM' => 'STORE_ID',
139 'AMOUNT' => 'QUANTITY',
140 'DATE' => 'ORDER_DELIVERY_BASKET.DELIVERY.DATE_DEDUCTED',
141 'BATCH_ID' => 'BATCH_BINDING.PRODUCT_BATCH_ID',
142 ],
143 'runtime' => [
144 new ReferenceField(
145 'BATCH_BINDING',
147 array('=this.ID' => 'ref.SHIPMENT_ITEM_STORE_ID'),
148 array('join_type' => 'left'),
149 ),
150 ],
151 'order' => ['DATE' => 'ASC'],
152 ]);
153
154 while ($element = $salesElements->fetch())
155 {
156 $element['DOCUMENT_TYPE'] = StoreDocumentTable::TYPE_SALES_ORDERS;
157 $registry[] = $element;
158 }
159 }
160
161 \Bitrix\Main\Type\Collection::sortByColumn($registry, ['DATE' => SORT_ASC]);
162
163 return $registry;
164 }
165}
static getList(array $parameters=array())