Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
StoreDocumentProvider.php
1<?php
2
4
15use Bitrix\Main;
16use Bitrix\Intranet;
21use Bitrix\UI\EntityEditor\ProviderWithUserFieldsTrait;
22use CCurrencyLang;
23
25{
26 use ProviderWithUserFieldsTrait {
27 getUfComponentFields as getUfComponentFieldsParent;
28 }
29
31 protected const GUID_PREFIX = 'STORE_DOCUMENT_DETAIL_';
32 protected const ENTITY_TYPE_NAME = 'store_document';
33 protected const PATH_TO_USER_PROFILE = '/company/personal/user/#user_id#/';
34
35 protected $document;
36 protected $config;
37 protected $userFieldInfos = null;
38 protected $createUfUrl = '';
39
42
43 protected static array $users = [];
44
45 protected function __construct(array $documentFields, array $config = [])
46 {
47 $this->document = $documentFields;
48 $this->config = $config;
49 $this->contractorsProvider = Contractor\Provider\Manager::getActiveProvider(
50 Contractor\Provider\Manager::PROVIDER_STORE_DOCUMENT
51 );
52 }
53
57 public function getConfigId(): string
58 {
59 return 'store_document_details';
60 }
61
67 public static function createByArray(array $documentFields, array $config = []): self
68 {
69 return new static($documentFields, $config);
70 }
71
77 public static function createById(int $id, array $config = []): self
78 {
79 $provider = new static(['ID' => $id], $config);
80 $provider->loadDocument();
81
82 return $provider;
83 }
84
90 public static function createByType(string $type, array $config = []): self
91 {
92 return new static(['DOC_TYPE' => $type], $config);
93 }
94
95 protected function getDocumentId(): ?int
96 {
97 return $this->document['ID'] ?? null;
98 }
99
100 protected function getDocumentType(): string
101 {
102 return $this->document['DOC_TYPE'] ?? static::DEFAULT_TYPE;
103 }
104
105 protected function isNewDocument(): bool
106 {
107 return $this->getDocumentId() === null;
108 }
109
110 protected function loadDocument(): void
111 {
112 if (!$this->isNewDocument())
113 {
114 $documentType = StoreDocumentTable::getRow(['select' => ['DOC_TYPE'], 'filter' => ['=ID' => $this->getDocumentId()]]);
115 if (!$documentType)
116 {
117 $this->document = [];
118 return;
119 }
120
121 $documentType = $documentType['DOC_TYPE'];
122
123 $tableClass = StoreDocumentTableManager::getTableClassByType($documentType) ?: StoreDocumentTable::class;
124 $document = $tableClass::getRow([
125 'select' => [
126 '*',
127 'UF_*',
128 'CONTRACTOR_REF_' => 'CONTRACTOR',
129 ],
130 'filter' => [
131 '=ID' => $this->getDocumentId(),
132 ],
133 ]);
134
135 $this->document = $document ? array_merge($this->document, $document) : [];
136 }
137 }
138
139 public function getGUID(): string
140 {
141 return static::GUID_PREFIX . $this->getDocumentType();
142 }
143
144 public function getEntityId(): ?int
145 {
146 return $this->getDocumentId();
147 }
148
149 public function getEntityTypeName(): string
150 {
151 return static::ENTITY_TYPE_NAME;
152 }
153
154 public function getEntityFields(): array
155 {
156 static $fields = [];
157
158 $documentType = $this->getDocumentType();
159 if (!isset($fields[$documentType]))
160 {
161 $documentTypeFields = $this->getDocumentFields();
162 $fields[$documentType] = $this->getAdditionalFieldKeys($documentTypeFields);
163 }
164
165 return $fields[$documentType];
166 }
167
168 protected function getDocumentFields(): array
169 {
170 return array_merge($this->getDocumentCommonFields(), $this->getDocumentSpecificFields());
171 }
172
173 protected function getDocumentCommonFields(): array
174 {
175 return [
176 [
177 'name' => 'ID',
178 'title' => static::getFieldTitle('ID'),
179 'type' => 'number',
180 'editable' => false,
181 'required' => false,
182 ],
183 [
184 'name' => 'TITLE',
185 'title' => static::getFieldTitle('TITLE'),
186 'type' => 'text',
187 'editable' => true,
188 'required' => false,
189 'isHeading' => true,
190 'visibilityPolicy' => 'edit',
191 'placeholders' => [
192 'creation' => $this->getDefaultDocumentTitle(),
193 ],
194 ],
195 [
196 'name' => 'DATE_CREATE',
197 'title' => static::getFieldTitle('DATE_CREATE'),
198 'type' => 'datetime',
199 'editable' => false,
200 'visibilityPolicy' => 'view',
201 ],
202 [
203 'name' => 'CREATED_BY',
204 'title' => static::getFieldTitle('CREATED_BY'),
205 'type' => 'user',
206 'editable' => false,
207 ],
208 [
209 'name' => 'RESPONSIBLE_ID',
210 'title' => static::getFieldTitle('RESPONSIBLE_ID'),
211 'type' => 'user',
212 'editable' => true,
213 'required' => true,
214 ],
215 array_merge(
216 [
217 'name' => 'TOTAL_WITH_CURRENCY',
218 'editable' => in_array(
219 $this->getDocumentType(),
220 [
223 ],
224 true
225 ),
226 ],
227 $this->isNewDocument()
230 ),
231 [
232 'name' => 'DATE_MODIFY',
233 'title' => static::getFieldTitle('DATE_MODIFY'),
234 'type' => 'datetime',
235 'editable' => false,
236 'visibilityPolicy' => 'view',
237 ],
238 [
239 'name' => 'MODIFIED_BY',
240 'title' => static::getFieldTitle('MODIFIED_BY'),
241 'type' => 'user',
242 'editable' => false,
243 'visibilityPolicy' => 'view',
244 ],
245 [
246 'name' => 'DATE_STATUS',
247 'title' => static::getFieldTitle('DATE_STATUS'),
248 'type' => 'datetime',
249 'editable' => false,
250 'visibilityPolicy' => 'view',
251 ],
252 [
253 'name' => 'STATUS_BY',
254 'title' => static::getFieldTitle('STATUS_BY'),
255 'type' => 'user',
256 'editable' => false,
257 'visibilityPolicy' => 'view',
258 ],
259 [
260 'name' => 'DOCUMENT_PRODUCTS',
261 'title' => Loc::getMessage('CATALOG_STORE_DOCUMENT_DETAIL_FIELD_DOCUMENT_PRODUCTS_2'),
262 'type' => 'product_row_summary',
263 'editable' => false,
264 ],
265 ];
266 }
267
268 protected function getTotalInfoControlForNewDocument(): array
269 {
270 return [
271 'title' => static::getFieldTitle('CURRENCY'),
272 'type' => 'list',
273 'data' => [
274 'items' => $this->prepareCurrencyList(),
275 ]
276 ];
277 }
278
279 protected function getTotalInfoControlForExistingDocument(): array
280 {
281 return [
282 'title' => static::getFieldTitle('TOTAL_WITH_CURRENCY'),
283 'type' => 'money',
284 'data' => [
285 'largeFormat' => true,
286 'affectedFields' => ['CURRENCY', 'TOTAL'],
287 'amount' => 'TOTAL',
288 'amountReadOnly' => true,
289 'currency' => [
290 'name' => 'CURRENCY',
291 'items' => $this->prepareCurrencyList(),
292 ],
293 'formatted' => 'FORMATTED_TOTAL',
294 'formattedWithCurrency' => 'FORMATTED_TOTAL_WITH_CURRENCY',
295 ],
296 ];
297 }
298
299 protected function getDocumentSpecificFields(): array
300 {
301 $fields = [];
302
303 switch ($this->getDocumentType())
304 {
306 $fields = [
307 [
308 'name' => 'DOC_NUMBER',
309 'title' => static::getFieldTitle('DOC_NUMBER'),
310 'type' => 'text',
311 'editable' => true,
312 'showAlways' => true,
313 ],
314 [
315 'name' => 'DATE_DOCUMENT',
316 'title' => static::getFieldTitle('DATE_DOCUMENT'),
317 'type' => 'datetime',
318 'editable' => true,
319 'data' => [
320 'enableTime' => false,
321 ],
322 ],
323 $this->getContractorField(),
324 [
325 'name' => 'ITEMS_ORDER_DATE',
326 'title' => static::getFieldTitle('ITEMS_ORDER_DATE'),
327 'type' => 'datetime',
328 'editable' => true,
329 'data' => [
330 'enableTime' => false,
331 ],
332 ],
333 [
334 'name' => 'ITEMS_RECEIVED_DATE',
335 'title' => static::getFieldTitle('ITEMS_RECEIVED_DATE'),
336 'type' => 'datetime',
337 'editable' => true,
338 'data' => [
339 'enableTime' => false,
340 ],
341 ],
342 [
343 'name' => 'DOCUMENT_FILES',
344 'title' => static::getFieldTitle('DOCUMENT_FILES'),
345 'type' => 'file',
346 'editable' => true,
347 'showAlways' => true,
348 'data' => [
349 'multiple' => true,
350 'maxFileSize' => \CUtil::Unformat(ini_get('upload_max_filesize')),
351 ]
352 ],
353 ];
354 break;
356 $fields = [
357 [
358 'name' => 'DOC_NUMBER',
359 'title' => static::getFieldTitle('DOC_NUMBER'),
360 'type' => 'text',
361 'editable' => true,
362 'showAlways' => false,
363 ],
364 [
365 'name' => 'DATE_DOCUMENT',
366 'title' => static::getFieldTitle('DATE_DOCUMENT'),
367 'type' => 'datetime',
368 'editable' => true,
369 'showAlways' => false,
370 'data' => [
371 'enableTime' => false,
372 ],
373 ],
374 ];
375 break;
377 $fields = [
378 [
379 'name' => 'DOC_NUMBER',
380 'title' => static::getFieldTitle('DOC_NUMBER'),
381 'type' => 'text',
382 'editable' => true,
383 'showAlways' => false,
384 ],
385 [
386 'name' => 'DATE_DOCUMENT',
387 'title' => static::getFieldTitle('DATE_DOCUMENT'),
388 'type' => 'datetime',
389 'editable' => true,
390 'showAlways' => false,
391 'data' => [
392 'enableTime' => false,
393 ],
394 ],
395 ];
396 break;
397 }
398
399 $fields = $this->fillUfEntityFields($fields);
400
401 return $fields;
402 }
403
404 protected function getUfComponentFields(): array
405 {
406 $result = $this->getUfComponentFieldsParent();
407 $result['USER_FIELD_CREATE_PAGE_URL'] = $this->createUfUrl;
408
409 return $result;
410 }
411
412 public function setCreateUfUrl(string $url): void
413 {
414 $this->createUfUrl = $url;
415 }
416
420 public function getUfEntityId(): string
421 {
422 /* @var StoreDocumentSpecificTable $tableClass */
423 $tableClass = StoreDocumentTableManager::getTableClassByType($this->getDocumentType());
424
425 if ($tableClass)
426 {
427 return $tableClass::getUfId();
428 }
429
430 return '';
431 }
432
436 public function getUfPrefix(): string
437 {
438 return 'CATALOG';
439 }
440
441 protected function getDefaultDocumentTitle(string $documentNumber = '')
442 {
443 return Loc::getMessage('CATALOG_STORE_DOCUMENT_DETAIL_TITLE_DEFAULT_NAME_'
444 . $this->getDocumentType(), ['%DOCUMENT_NUMBER%' => $documentNumber]);
445 }
446
447 protected function getAdditionalFieldKeys($fields): array
448 {
449 $resultFields = [];
450
451 foreach ($fields as $field)
452 {
453 $fieldName = $field['name'];
454 $fieldType = $field['type'];
455
456 if ($fieldType === 'user')
457 {
458 $field['data'] = [
459 'enableEditInView' => $field['editable'],
460 'formated' => $fieldName . '_FORMATTED_NAME',
461 'photoUrl' => $fieldName . '_PHOTO_URL',
462 'showUrl' => 'PATH_TO_' . $fieldName,
463 'pathToProfile' => static::PATH_TO_USER_PROFILE,
464 ];
465 }
466
467 $resultFields[] = $field;
468 }
469
470 return $resultFields;
471 }
472
473 public function getEntityConfig(): array
474 {
475 $sectionElements = [
476 [
477 'name' => 'main',
478 'title' => Loc::getMessage('CATALOG_STORE_DOCUMENT_DETAIL_MAIN_SECTION'),
479 'type' => 'section',
480 'elements' => $this->getMainSectionElements(),
481 'data' => [
482 'isRemovable' => 'false',
483 ],
484 'sort' => 100,
485 ],
486 ];
487
488 $sectionElements[] = [
489 'name' => 'products',
490 'title' => Loc::getMessage('CATALOG_STORE_DOCUMENT_DETAIL_PRODUCTS_SECTION'),
491 'type' => 'section',
492 'elements' => [
493 ['name' => 'DOCUMENT_PRODUCTS'],
494 ],
495 'data' => [
496 'isRemovable' => 'false',
497 ],
498 'sort' => 200,
499 ];
500
501 $sectionElements[] = [
502 'name' => 'extra',
503 'title' => Loc::getMessage('CATALOG_STORE_DOCUMENT_DETAIL_EXTRA_SECTION'),
504 'type' => 'section',
505 'elements' => [
506 ['name' => 'RESPONSIBLE_ID'],
507 ],
508 'data' => [
509 'isRemovable' => 'false',
510 ],
511 'sort' => 300,
512 ];
513
514 Main\Type\Collection::sortByColumn($sectionElements, ['sort' => SORT_ASC]);
515
516 return [
517 [
518 'name' => 'left',
519 'type' => 'column',
520 'data' => [
521 'width' => 40,
522 ],
523 'elements' => $sectionElements,
524 ],
525 ];
526 }
527
528 public function getMainSectionElements()
529 {
530 $ufSectionElements = [];
531 $ufInfos = $this->getUfEntityFields();
532 foreach ($ufInfos as $userField)
533 {
534 $ufSectionElements[] = ['name' => $userField['name']];
535 }
536
537 switch ($this->getDocumentType())
538 {
540 return [
541 ['name' => 'TITLE'],
542 ['name' => 'TOTAL_WITH_CURRENCY'],
543 ['name' => 'CONTRACTOR_ID'],
544 ['name' => 'DOC_NUMBER'],
545 ['name' => 'DATE_DOCUMENT'],
546 ['name' => 'ITEMS_RECEIVED_DATE'],
547 ['name' => 'DOCUMENT_FILES'],
548 ...$ufSectionElements,
549 ];
551 return [
552 ['name' => 'TITLE'],
553 ['name' => 'TOTAL_WITH_CURRENCY'],
554 ...$ufSectionElements,
555 ];
557 return [
558 ['name' => 'TITLE'],
559 ['name' => 'TOTAL_WITH_CURRENCY'],
560 ...$ufSectionElements,
561 ];
563 return [
564 ['name' => 'TITLE'],
565 ['name' => 'TOTAL_WITH_CURRENCY'],
566 ...$ufSectionElements,
567 ];
568 default:
569 return $ufSectionElements;
570 }
571 }
572
573 public function getEntityData(): array
574 {
575 if ($this->isNewDocument())
576 {
577 $document = array_fill_keys(array_column($this->getEntityFields(), 'name'), null);
578 $document = array_merge($document, [
579 'DOC_TYPE' => $this->document['DOC_TYPE'],
580 'RESPONSIBLE_ID' => CurrentUser::get()->getId(),
581 ]);
582 }
583 else
584 {
586 }
587
588 $currency = $this->document['CURRENCY'] ?? null;
589 if (!$currency)
590 {
591 $currency = CurrencyManager::getBaseCurrency();
592 }
593
594 if (!isset($document['TOTAL']))
595 {
596 $document['TOTAL'] = 0;
597 $document['CURRENCY'] = $currency;
598 }
599
600 $document['FORMATTED_TOTAL'] = CCurrencyLang::CurrencyFormat($document['TOTAL'], $currency, false);
601 $document['FORMATTED_TOTAL_WITH_CURRENCY'] = CCurrencyLang::CurrencyFormat($document['TOTAL'],
602 $currency);
603
604 if (empty($this->config['skipProducts']))
605 {
606 $document['DOCUMENT_PRODUCTS'] = $this->getDocumentProductsPreview($document);
607 }
608 if (empty($this->config['skipFiles']))
609 {
610 $document['DOCUMENT_FILES'] = $this->getDocumentFiles($document);
611 }
612
613 if ($this->shouldPrepareDateFields())
614 {
615 $dateFields = ['DATE_DOCUMENT', 'ITEMS_ORDER_DATE', 'ITEMS_RECEIVED_DATE'];
616 foreach ($dateFields as $dateField)
617 {
618 if (isset($document[$dateField]) && $document[$dateField] instanceof Main\Type\DateTime)
619 {
620 $document[$dateField] = new Main\Type\Date($document[$dateField]);
621 }
622 }
623 }
624
625 $document = $this->fillUfEntityData($document);
626
628 }
629
630 protected function getDocumentFiles(array $document)
631 {
632 if ($this->isNewDocument())
633 {
634 return [];
635 }
636
637 $files = StoreDocumentFileTable::getList(['select' => ['FILE_ID'], 'filter' => ['DOCUMENT_ID' => $this->document['ID']]])->fetchAll();
638
639 return array_column($files, 'FILE_ID');
640 }
641
642 protected function getDocumentProductsPreview(array $document): array
643 {
644 $documentProductSummaryInfo = $this->getProductSummaryInfo($document);
645 $documentProductSummaryInfo['isReadOnly'] = $this->isReadOnly();
646
647 return $documentProductSummaryInfo;
648 }
649
650 private function getProductSummaryInfo(array $document): array
651 {
652 $isNewDocument = $document['ID'] === null;
653 if ($isNewDocument)
654 {
655 return [
656 'count' => 0,
657 'total' => \CCurrencyLang::CurrencyFormat(0, $document['CURRENCY']),
658 'totalRaw' => [
659 'amount' => 0,
660 'currency' => $document['CURRENCY'],
661 ],
662 'items' => [],
663 ];
664 }
665
666 $storeDocumentProductPositionRepository = StoreDocumentProductPositionRepository::getInstance();
667 $productPositionList = $storeDocumentProductPositionRepository->getList($document['ID']);
668 foreach ($productPositionList as &$productPosition)
669 {
670 $productPosition['SUM'] = \CCurrencyLang::CurrencyFormat($productPosition['SUM'], $document['CURRENCY']);
671 }
672
673 return [
674 'count' => $storeDocumentProductPositionRepository->getCount($document['ID']),
675 'total' => \CCurrencyLang::CurrencyFormat($document['TOTAL'], $document['CURRENCY']),
676 'totalRaw' => [
677 'amount' => $document['TOTAL'],
678 'currency' => $document['CURRENCY'],
679 ],
680 'items' => $productPositionList,
681 ];
682 }
683
684 protected function getAdditionalDocumentData(array $document): array
685 {
686 $userFields = [];
687
688 foreach ($this->getEntityFields() as $field)
689 {
690 $fieldName = $field['name'];
691 $fieldType = $field['type'];
692
693 if ($fieldType === 'user')
694 {
695 $userId = $document[$field['name']] ?? null;
696 if (!$userId && $fieldName === 'CREATED_BY')
697 {
698 $userId = CurrentUser::get()->getId();
699 }
700
701 $userFields[$fieldName] = $userId;
702 }
703 }
704
705 $document['PATH_TO_USER_PROFILE'] = static::PATH_TO_USER_PROFILE;
706
708 {
709 $document = array_merge($document, $this->getContractorData($document));
710 }
711
712 $uniqueUserIds = array_filter(array_unique(array_values($userFields)));
713 if (!empty($uniqueUserIds) && empty($this->config['skipUsers']))
714 {
715 $document = $this->getAdditionalUserData($document, $userFields, $this->getUsersInfo($uniqueUserIds));
716 }
717 elseif(!empty($uniqueUserIds) && !empty($document['USER_INFO']))
718 {
719 $document = $this->getAdditionalUserData($document, $userFields, $document['USER_INFO']);
720 }
721
722 return $document;
723 }
724
728 protected function getContractorField(): array
729 {
730 return [
731 'name' => 'CONTRACTOR_ID',
732 'title' => static::getFieldTitle('CONTRACTOR_ID'),
733 'type' => $this->contractorsProvider
734 ? $this->contractorsProvider::getEditorFieldType()
735 : 'contractor',
736 'editable' => true,
737 'required' => true,
738 'data' => $this->contractorsProvider
739 ? $this->contractorsProvider::getEditorFieldData()
740 : [
741 'contractorName' => 'CONTRACTOR_NAME',
742 ],
743 ];
744 }
745
750 protected function getContractorData(array $document): array
751 {
752 return $this->contractorsProvider
753 ? $this->contractorsProvider::getEditorEntityData((int)$document['ID'])
754 : ['CONTRACTOR_NAME' => $this->getContractorName()];
755 }
756
760 protected function getContractorName(): string
761 {
762 if (!empty($this->document['CONTRACTOR_REF_COMPANY']))
763 {
764 return $this->document['CONTRACTOR_REF_COMPANY'];
765 }
766
767 if (!empty($this->document['CONTRACTOR_REF_PERSON_NAME']))
768 {
769 return $this->document['CONTRACTOR_REF_PERSON_NAME'];
770 }
771
772 return '';
773 }
774
775 protected function getUsersInfo(array $userIds): array
776 {
777 Main\Type\Collection::normalizeArrayValuesByInt($userIds);
778 if (empty($userIds))
779 {
780 return [];
781 }
782
783 $usersInfo = [];
784
785 $newUsers = [];
786 foreach ($userIds as $id)
787 {
788 if (isset(static::$users[$id]))
789 {
790 $usersInfo[$id] = static::$users[$id];
791 }
792 else
793 {
794 $newUsers[] = $id;
795 }
796 }
797
798 if (empty($newUsers))
799 {
800 return $usersInfo;
801 }
802
803 foreach (array_chunk($newUsers, CATALOG_PAGE_SIZE) as $pageIds)
804 {
805 $userList = UserTable::getList([
806 'select' => [
807 'ID',
808 'LOGIN',
809 'NAME',
810 'SECOND_NAME',
811 'LAST_NAME',
812 'PERSONAL_PHOTO',
813 'WORK_POSITION',
814 ],
815 'filter' => [
816 '@ID' => $pageIds,
817 ],
818 ]);
819 while ($user = $userList->fetch())
820 {
821 $id = (int)$user['ID'];
822 $usersInfo[$id] = $user;
823 static::$users[$id] = $user;
824 }
825 unset($userList);
826 }
827
828 return $usersInfo;
829 }
830
831 protected function getAdditionalUserData(array $document, array $userFields, array $usersInfo): array
832 {
833 foreach ($userFields as $fieldName => $userId)
834 {
835 if (!$userId)
836 {
837 continue;
838 }
839
840 $user = $usersInfo[$userId];
841 $document['PATH_TO_' . $fieldName] = \CComponentEngine::MakePathFromTemplate(
842 static::PATH_TO_USER_PROFILE,
843 ['user_id' => $user['ID']]
844 );
845
846 $document[$fieldName . '_FORMATTED_NAME'] = \CUser::FormatName(
847 \CSite::GetNameFormat(),
848 [
849 'ID' => $user['ID'] ?? '',
850 'LOGIN' => $user['LOGIN'],
851 'NAME' => $user['NAME'],
852 'LAST_NAME' => $user['LAST_NAME'],
853 'SECOND_NAME' => $user['SECOND_NAME'],
854 ],
855 true,
856 false
857 );
858
859 $personalPhoto = (int)($user['PERSONAL_PHOTO'] ?? 0);
860 if ($personalPhoto > 0)
861 {
862 $fileInfo = \CFile::ResizeImageGet(
863 $personalPhoto,
864 [
865 'width' => 60,
866 'height' => 60,
867 ],
868 BX_RESIZE_IMAGE_EXACT
869 );
870 if (isset($fileInfo['src']))
871 {
872 $document[$fieldName . '_PHOTO_URL'] = $fileInfo['src'];
873 }
874 }
875 }
876
877 return $document;
878 }
879
880 public function getEntityControllers(): array
881 {
882 return [
883 [
884 'name' => 'PRODUCT_LIST_CONTROLLER',
885 'type' => 'catalog_store_document_product_list',
886 'config' => [],
887 ],
888 [
889 'name' => 'DOCUMENT_CARD_CONTROLLER',
890 'type' => 'document_card',
891 'config' => [],
892 ],
893 ];
894 }
895
896 public function isReadOnly(): bool
897 {
899 $accessController = AccessController::getCurrent();
900
901 return
902 !$accessController->checkByValue(
903 ActionDictionary::ACTION_STORE_DOCUMENT_MODIFY,
904 $this->getDocumentType()
905 )
906 || (
907 isset($this->document['STATUS']) && $this->document['STATUS'] === 'Y'
908 )
909 ;
910 }
911
912 public function isEntityConfigEditable(): bool
913 {
915 $accessController = AccessController::getCurrent();
916
917 return AccessController::getCurrent()->check(ActionDictionary::ACTION_STORE_DOCUMENT_CARD_EDIT);
918 }
919
923 protected function prepareCurrencyList(): array
924 {
925 $result = [];
926
927 $existingCurrencies = CurrencyTable::getList([
928 'select' => [
929 'CURRENCY',
930 'FULL_NAME' => 'CURRENT_LANG_FORMAT.FULL_NAME',
931 'SORT',
932 ],
933 'order' => [
934 'BASE' => 'DESC',
935 'SORT' => 'ASC',
936 'CURRENCY' => 'ASC',
937 ],
938 ])->fetchAll();
939 foreach ($existingCurrencies as $currency)
940 {
941 $result[] = $this->prepareCurrencyListItem($currency);
942 }
943
944 return $result;
945 }
946
951 protected function prepareCurrencyListItem(array $currency): array
952 {
953 return [
954 'NAME' => $currency['FULL_NAME'],
955 'VALUE' => $currency['CURRENCY'],
956 ];
957 }
958
959 public static function getFieldTitle($fieldName)
960 {
961 switch ($fieldName)
962 {
963 case 'ID':
964 return Loc::getMessage('CATALOG_STORE_DOCUMENT_DETAIL_FIELD_ID');
965 case 'TITLE':
966 return Loc::getMessage('CATALOG_STORE_DOCUMENT_DETAIL_TITLE_ID');
967 case 'TOTAL_WITH_CURRENCY':
968 return Loc::getMessage('CATALOG_STORE_DOCUMENT_DETAIL_FIELD_TOTAL');
969 case 'CURRENCY':
970 return Loc::getMessage('CATALOG_STORE_DOCUMENT_DETAIL_FIELD_CURRENCY');
971 case 'ITEMS_ORDER_DATE':
972 return Loc::getMessage('CATALOG_STORE_DOCUMENT_DETAIL_ITEMS_ORDER_DATE_DOCUMENT');
973 case 'ITEMS_RECEIVED_DATE':
974 return Loc::getMessage('CATALOG_STORE_DOCUMENT_DETAIL_ITEMS_RECEIVED_DATE_DOCUMENT');
975 case 'DOCUMENT_FILES':
976 return Loc::getMessage('CATALOG_STORE_DOCUMENT_DETAIL_FIELD_DOCUMENT_FILES_2');
977 default:
978 return Loc::getMessage('CATALOG_STORE_DOCUMENT_DETAIL_FIELD_' . $fieldName);
979 }
980 }
981
982 protected function shouldPrepareDateFields(): bool
983 {
984 return true;
985 }
986}
getAdditionalUserData(array $document, array $userFields, array $usersInfo)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getRow(array $parameters)
static getList(array $parameters=array())