Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
documentdataprovider.php
1<?php
2
4
18
19\CBitrixComponent::includeComponentClass('bitrix:catalog.store.document.list');
20
22{
23 private $mode;
24
25 private Settings $settings;
26
27 private static $fieldsOrder = [
28 \CatalogStoreDocumentListComponent::ARRIVAL_MODE => [
29 'ID',
30 'TITLE',
31 'DOC_NUMBER',
32 'DOC_TYPE',
33 'DATE_DOCUMENT',
34 'STATUS',
35 'DATE_CREATE',
36 'DATE_MODIFY',
37 'DATE_STATUS',
38 'STATUS_BY',
39 'RESPONSIBLE_ID',
40 'CREATED_BY',
41 'MODIFIED_BY',
42 'CONTRACTOR_ID',
43 'TOTAL',
44 'STORES',
45 ],
46 \CatalogStoreDocumentListComponent::MOVING_MODE => [
47 'ID',
48 'TITLE',
49 'DOC_NUMBER',
50 'DOC_TYPE',
51 'DATE_DOCUMENT',
52 'STATUS',
53 'DATE_CREATE',
54 'DATE_MODIFY',
55 'DATE_STATUS',
56 'STATUS_BY',
57 'RESPONSIBLE_ID',
58 'CREATED_BY',
59 'MODIFIED_BY',
60 'TOTAL',
61 'STORES_FROM',
62 'STORES_TO',
63 ],
64 \CatalogStoreDocumentListComponent::DEDUCT_MODE => [
65 'ID',
66 'TITLE',
67 'DOC_NUMBER',
68 'DOC_TYPE',
69 'DATE_DOCUMENT',
70 'STATUS',
71 'DATE_CREATE',
72 'DATE_MODIFY',
73 'DATE_STATUS',
74 'STATUS_BY',
75 'RESPONSIBLE_ID',
76 'CREATED_BY',
77 'MODIFIED_BY',
78 'TOTAL',
79 'STORES',
80 ],
81 \CatalogStoreDocumentListComponent::OTHER_MODE => [
82 'ID',
83 'TITLE',
84 'DATE_DOCUMENT',
85 'STATUS',
86 'DATE_CREATE',
87 'DATE_MODIFY',
88 'DATE_STATUS',
89 'STATUS_BY',
90 'CREATED_BY',
91 'MODIFIED_BY',
92 ],
93 ];
94
95 private static $fields;
96
98 private ?IProvider $contractorsProvider;
99
100 public function __construct($mode, Settings $settings)
101 {
102 $this->settings = $settings;
103 $this->contractorsProvider = Manager::getActiveProvider(Manager::PROVIDER_STORE_DOCUMENT);
104
105 $this->mode = $mode;
106 self::$fields = [
107 'ID' => [
108 'id' => 'ID',
109 'name' => Loc::getMessage('DOCUMENT_ID_NAME'),
110 'default' => false,
111 'sort' => 'ID',
112 ],
113 'TITLE' => [
114 'id' => 'TITLE',
115 'name' => Loc::getMessage('DOCUMENT_TITLE_NAME'),
116 'default' => true,
117 'sort' => 'TITLE',
118 'width' => '215',
119 ],
120 'DOC_NUMBER' => [
121 'id' => 'DOC_NUMBER',
122 'name' => Loc::getMessage('DOCUMENT_DOC_NUMBER_NAME'),
123 'default' => $this->mode === \CatalogStoreDocumentListComponent::ARRIVAL_MODE,
124 'sort' => 'DOC_NUMBER',
125 ],
126 'DOC_TYPE' => [
127 'id' => 'DOC_TYPE',
128 'name' => Loc::getMessage('DOCUMENT_TYPE_NAME'),
129 'default' => $this->mode === \CatalogStoreDocumentListComponent::ARRIVAL_MODE,
130 'sort' => 'DOC_TYPE',
131 'type' => Column\Type::LABELS,
132 ],
133 'DATE_DOCUMENT' => [
134 'id' => 'DATE_DOCUMENT',
135 'name' => Loc::getMessage('DOCUMENT_DATE_DOCUMENT_NAME'),
136 'default' => false,
137 'sort' => 'DATE_DOCUMENT',
138 ],
139 'STATUS' => [
140 'id' => 'STATUS',
141 'name' => Loc::getMessage('DOCUMENT_STATUS_NAME'),
142 'default' => true,
143 'sort' => 'STATUS',
144 'type' => Column\Type::LABELS,
145 ],
146 'DATE_CREATE' => [
147 'id' => 'DATE_CREATE',
148 'name' => Loc::getMessage('DOCUMENT_DATE_CREATE_NAME'),
149 'default' => false,
150 'sort' => 'DATE_CREATE',
151 ],
152 'DATE_MODIFY' => [
153 'id' => 'DATE_MODIFY',
154 'name' => Loc::getMessage('DOCUMENT_DATE_MODIFY_NAME'),
155 'default' => true,
156 'sort' => 'DATE_MODIFY',
157 ],
158 'DATE_STATUS' => [
159 'id' => 'DATE_STATUS',
160 'name' => Loc::getMessage('DOCUMENT_DATE_STATUS_NAME'),
161 'default' => false,
162 'sort' => 'DATE_STATUS',
163 ],
164 'STATUS_BY' => [
165 'id' => 'STATUS_BY',
166 'name' => Loc::getMessage('DOCUMENT_STATUS_BY_NAME'),
167 'default' => false,
168 'sort' => 'STATUS_BY',
169 ],
170 'RESPONSIBLE_ID' => [
171 'id' => 'RESPONSIBLE_ID',
172 'name' => Loc::getMessage('DOCUMENT_RESPONSIBLE_ID_NAME'),
173 'default' => true,
174 'sort' => 'RESPONSIBLE_ID',
175 ],
176 'CREATED_BY' => [
177 'id' => 'CREATED_BY',
178 'name' => Loc::getMessage('DOCUMENT_CREATED_BY_NAME'),
179 'default' => false,
180 'sort' => 'CREATED_BY',
181 ],
182 'MODIFIED_BY' => [
183 'id' => 'MODIFIED_BY',
184 'name' => Loc::getMessage('DOCUMENT_MODIFIED_BY_NAME'),
185 'default' => false,
186 'sort' => 'MODIFIED_BY',
187 ],
188 'CONTRACTOR_ID' => [
189 'id' => 'CONTRACTOR_ID',
190 'name' => Loc::getMessage('DOCUMENT_CONTRACTOR_ID_NAME'),
191 'default' => true,
192 'sort' => 'CONTRACTOR_ID',
193 ],
194 'TOTAL' => [
195 'id' => 'TOTAL',
196 'name' => Loc::getMessage('DOCUMENT_TOTAL_NAME'),
197 'default' => true,
198 'sort' => 'TOTAL',
199 ],
200 'STORES' => [
201 'id' => 'STORES',
202 'name' => Loc::getMessage('DOCUMENT_STORES_NAME'),
203 'default' => true,
204 'sort' => false,
205 'type' => Column\Type::LABELS,
206 ],
207 'STORES_FROM' => [
208 'id' => 'STORES_FROM',
209 'name' => Loc::getMessage('DOCUMENT_STORES_FROM_NAME'),
210 'default' => true,
211 'sort' => false,
212 'type' => Column\Type::LABELS,
213 ],
214 'STORES_TO' => [
215 'id' => 'STORES_TO',
216 'name' => Loc::getMessage('DOCUMENT_STORES_TO_NAME'),
217 'default' => true,
218 'sort' => false,
219 'type' => Column\Type::LABELS,
220 ],
221 ];
222 }
223
224 public function getSettings()
225 {
226 return $this->settings;
227 }
228
229 public function prepareFields()
230 {
231 $fields = [
232 'TITLE' => $this->createField('TITLE', [
233 'default' => true,
234 ]),
235 'ID' => $this->createField('ID', [
236 'type' => 'number',
237 ]),
238 'STATUS' => $this->createField('STATUS', [
239 'default' => true,
240 'type' => 'list',
241 'partial' => true,
242 ]),
243 'DATE_DOCUMENT' => $this->createField('DATE_DOCUMENT', [
244 'default' => true,
245 'type' => 'date',
246 ]),
247 'DATE_CREATE' => $this->createField('DATE_CREATE', [
248 'type' => 'date',
249 ]),
250 'DATE_MODIFY' => $this->createField('DATE_MODIFY', [
251 'type' => 'date',
252 ]),
253 'DATE_STATUS' => $this->createField('DATE_STATUS', [
254 'type' => 'date',
255 ]),
256 'STATUS_BY' => $this->createField('STATUS_BY', [
257 'partial' => true,
258 'type' => 'entity_selector',
259 ]),
260 'RESPONSIBLE_ID' => $this->createField('RESPONSIBLE_ID', [
261 'default' => true,
262 'partial' => true,
263 'type' => 'entity_selector',
264 ]),
265 'CREATED_BY' => $this->createField('CREATED_BY', [
266 'partial' => true,
267 'type' => 'entity_selector',
268 ]),
269 'MODIFIED_BY' => $this->createField('MODIFIED_BY', [
270 'partial' => true,
271 'type' => 'entity_selector',
272 ]),
273 ];
274
275 if (Loader::includeModule('crm'))
276 {
277 $fields['PRODUCTS'] = $this->createField('PRODUCTS', [
278 'partial' => true,
279 'type' => 'entity_selector',
280 ]);
281 }
282
283 if ($this->mode !== \CatalogStoreDocumentListComponent::OTHER_MODE)
284 {
285 $fields['DOC_NUMBER'] = $this->createField('DOC_NUMBER');
286
287 if ($this->mode === \CatalogStoreDocumentListComponent::MOVING_MODE)
288 {
289 $fields['STORES_FROM'] = $this->createField('STORES_FROM', [
290 'partial' => true,
291 'default' => true,
292 'type' => 'entity_selector',
293 ]);
294 $fields['STORES_TO'] = $this->createField('STORES_TO', [
295 'partial' => true,
296 'default' => true,
297 'type' => 'entity_selector',
298 ]);
299 }
300 else
301 {
302 $fields['STORES'] = $this->createField('STORES', [
303 'partial' => true,
304 'type' => 'entity_selector',
305 ]);
306 }
307 }
308
309 if ($this->mode === \CatalogStoreDocumentListComponent::ARRIVAL_MODE)
310 {
311 if ($this->contractorsProvider)
312 {
313 $contractorsFields = $this->contractorsProvider::getDocumentsGridFilterFields();
314 foreach ($contractorsFields as $contractorsField)
315 {
316 $fields[$contractorsField['CODE']] = $this->createField(
317 $contractorsField['CODE'],
318 $contractorsField['PARAMS']
319 );
320 }
321 }
322 else
323 {
324 $fields['CONTRACTOR_ID'] = $this->createField('CONTRACTOR_ID', [
325 'partial' => true,
326 'type' => 'entity_selector',
327 'default' => true,
328 ]);
329 }
330
331 $fields['DOC_TYPE'] = $this->createField('DOC_TYPE', [
332 'default' => true,
333 'type' => 'list',
334 'partial' => 'true'
335 ]);
336 }
337
338 return $fields;
339 }
340
341 protected function getFieldName($fieldID)
342 {
343 return Loc::getMessage("DOCUMENT_{$fieldID}_NAME");
344 }
345
349 public function prepareFieldData($fieldID)
350 {
351 if ($fieldID === 'STATUS')
352 {
353 return [
354 'params' => [
355 'multiple' => 'Y',
356 ],
358 ];
359 }
360
361 if ($fieldID === 'DOC_TYPE')
362 {
363 if ($this->mode === \CatalogStoreDocumentListComponent::ARRIVAL_MODE)
364 {
365 return [
366 'params' => [
367 'multiple' => 'Y',
368 ],
369 'items' => [
372 ]
373 ];
374 }
375 }
376
377 $userFields = ['RESPONSIBLE_ID', 'STATUS_BY', 'CREATED_BY', 'MODIFIED_BY'];
378 if (in_array($fieldID, $userFields))
379 {
380 return $this->getUserEntitySelectorParams($this->mode . '_' . $fieldID . '_filter', ['fieldName' => $fieldID]);
381 }
382
383 if (in_array($fieldID, ['STORES', 'STORES_FROM', 'STORES_TO'], true))
384 {
385 return [
386 'params' => [
387 'multiple' => 'Y',
388 'dialogOptions' => [
389 'height' => 200,
390 'context' => $this->mode . '_store_filter',
391 'entities' => [
392 [
393 'id' => 'store',
394 'dynamicLoad' => true,
395 'dynamicSearch' => true,
396 ]
397 ],
398 'dropdownMode' => false,
399 ],
400 ],
401 ];
402 }
403
404 if ($fieldID === 'CONTRACTOR_ID')
405 {
406 return [
407 'params' => [
408 'multiple' => 'Y',
409 'dialogOptions' => [
410 'height' => 200,
411 'context' => $this->mode . '_contractor_filter',
412 'entities' => [
413 [
414 'id' => 'contractor',
415 'dynamicLoad' => true,
416 'dynamicSearch' => true,
417 ]
418 ],
419 'dropdownMode' => false,
420 ],
421 ],
422 ];
423 }
424
425 if (
426 $this->contractorsProvider
427 && $this->contractorsProvider::isDocumentsGridFilterFieldSupported($fieldID)
428 )
429 {
430 return $this->contractorsProvider::getDocumentsGridFilterFieldData($fieldID);
431 }
432
433 if ($fieldID === 'PRODUCTS')
434 {
435 return [
436 'params' => [
437 'multiple' => 'Y',
438 'dialogOptions' => [
439 'height' => 200,
440 'context' => $this->mode . '_product_filter',
441 'entities' => [
442 [
443 'id' => 'product',
444 'options' => [
445 'iblockId' => \Bitrix\Crm\Product\Catalog::getDefaultId(),
446 'basePriceId' => Catalog\GroupTable::getBasePriceTypeId(),
447 ],
448 ]
449 ],
450 'dropdownMode' => false,
451 ],
452 ],
453 ];
454 }
455
456 return null;
457 }
458
459 public function getGridColumns()
460 {
461 $columns = [];
462 $fieldsOrder = self::$fieldsOrder[$this->mode];
463 foreach ($fieldsOrder as $field)
464 {
465 $columns[] = self::$fields[$field];
466 }
467
468 switch ($this->mode)
469 {
470 case \CatalogStoreDocumentListComponent::ARRIVAL_MODE:
471 $gridUFManager = new \Bitrix\Main\Grid\Uf\Base(StoreDocumentArrivalTable::getUfId());
472 $gridUFManager->addUFHeaders($columns);
473 $gridUFManager = new \Bitrix\Main\Grid\Uf\Base(StoreDocumentStoreAdjustmentTable::getUfId());
474 $gridUFManager->addUFHeaders($columns);
475 break;
476 case \CatalogStoreDocumentListComponent::MOVING_MODE:
477 $gridUFManager = new \Bitrix\Main\Grid\Uf\Base(StoreDocumentMovingTable::getUfId());
478 $gridUFManager->addUFHeaders($columns);
479 break;
480 case \CatalogStoreDocumentListComponent::DEDUCT_MODE:
481 $gridUFManager = new \Bitrix\Main\Grid\Uf\Base(StoreDocumentDeductTable::getUfId());
482 $gridUFManager->addUFHeaders($columns);
483 break;
484 }
485
486
487 return $columns;
488 }
489}
getUserEntitySelectorParams(string $context, array $params)
createField($fieldID, array $params=null)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29