21use Bitrix\UI\EntityEditor\ProviderWithUserFieldsTrait;
26 use ProviderWithUserFieldsTrait {
47 $this->document = $documentFields;
49 $this->contractorsProvider = Contractor\Provider\Manager::getActiveProvider(
50 Contractor\
Provider\Manager::PROVIDER_STORE_DOCUMENT
59 return 'store_document_details';
69 return new static($documentFields,
$config);
79 $provider =
new static([
'ID' => $id],
$config);
80 $provider->loadDocument();
92 return new static([
'DOC_TYPE' => $type],
$config);
97 return $this->document[
'ID'] ??
null;
102 return $this->document[
'DOC_TYPE'] ?? static::DEFAULT_TYPE;
117 $this->document = [];
121 $documentType = $documentType[
'DOC_TYPE'];
123 $tableClass = StoreDocumentTableManager::getTableClassByType($documentType) ?: StoreDocumentTable::class;
128 'CONTRACTOR_REF_' =>
'CONTRACTOR',
151 return static::ENTITY_TYPE_NAME;
159 if (!isset($fields[$documentType]))
165 return $fields[$documentType];
178 'title' => static::getFieldTitle(
'ID'),
185 'title' => static::getFieldTitle(
'TITLE'),
190 'visibilityPolicy' =>
'edit',
196 'name' =>
'DATE_CREATE',
197 'title' => static::getFieldTitle(
'DATE_CREATE'),
198 'type' =>
'datetime',
200 'visibilityPolicy' =>
'view',
203 'name' =>
'CREATED_BY',
204 'title' => static::getFieldTitle(
'CREATED_BY'),
209 'name' =>
'RESPONSIBLE_ID',
210 'title' => static::getFieldTitle(
'RESPONSIBLE_ID'),
217 'name' =>
'TOTAL_WITH_CURRENCY',
218 'editable' => in_array(
232 'name' =>
'DATE_MODIFY',
233 'title' => static::getFieldTitle(
'DATE_MODIFY'),
234 'type' =>
'datetime',
236 'visibilityPolicy' =>
'view',
239 'name' =>
'MODIFIED_BY',
240 'title' => static::getFieldTitle(
'MODIFIED_BY'),
243 'visibilityPolicy' =>
'view',
246 'name' =>
'DATE_STATUS',
247 'title' => static::getFieldTitle(
'DATE_STATUS'),
248 'type' =>
'datetime',
250 'visibilityPolicy' =>
'view',
253 'name' =>
'STATUS_BY',
254 'title' => static::getFieldTitle(
'STATUS_BY'),
257 'visibilityPolicy' =>
'view',
260 'name' =>
'DOCUMENT_PRODUCTS',
261 'title' =>
Loc::getMessage(
'CATALOG_STORE_DOCUMENT_DETAIL_FIELD_DOCUMENT_PRODUCTS_2'),
262 'type' =>
'product_row_summary',
271 'title' => static::getFieldTitle(
'CURRENCY'),
282 'title' => static::getFieldTitle(
'TOTAL_WITH_CURRENCY'),
285 'largeFormat' =>
true,
286 'affectedFields' => [
'CURRENCY',
'TOTAL'],
288 'amountReadOnly' =>
true,
290 'name' =>
'CURRENCY',
293 'formatted' =>
'FORMATTED_TOTAL',
294 'formattedWithCurrency' =>
'FORMATTED_TOTAL_WITH_CURRENCY',
308 'name' =>
'DOC_NUMBER',
309 'title' => static::getFieldTitle(
'DOC_NUMBER'),
312 'showAlways' =>
true,
315 'name' =>
'DATE_DOCUMENT',
316 'title' => static::getFieldTitle(
'DATE_DOCUMENT'),
317 'type' =>
'datetime',
320 'enableTime' =>
false,
325 'name' =>
'ITEMS_ORDER_DATE',
326 'title' => static::getFieldTitle(
'ITEMS_ORDER_DATE'),
327 'type' =>
'datetime',
330 'enableTime' =>
false,
334 'name' =>
'ITEMS_RECEIVED_DATE',
335 'title' => static::getFieldTitle(
'ITEMS_RECEIVED_DATE'),
336 'type' =>
'datetime',
339 'enableTime' =>
false,
343 'name' =>
'DOCUMENT_FILES',
344 'title' => static::getFieldTitle(
'DOCUMENT_FILES'),
347 'showAlways' =>
true,
350 'maxFileSize' => \CUtil::Unformat(ini_get(
'upload_max_filesize')),
358 'name' =>
'DOC_NUMBER',
359 'title' => static::getFieldTitle(
'DOC_NUMBER'),
362 'showAlways' =>
false,
365 'name' =>
'DATE_DOCUMENT',
366 'title' => static::getFieldTitle(
'DATE_DOCUMENT'),
367 'type' =>
'datetime',
369 'showAlways' =>
false,
371 'enableTime' =>
false,
379 'name' =>
'DOC_NUMBER',
380 'title' => static::getFieldTitle(
'DOC_NUMBER'),
383 'showAlways' =>
false,
386 'name' =>
'DATE_DOCUMENT',
387 'title' => static::getFieldTitle(
'DATE_DOCUMENT'),
388 'type' =>
'datetime',
390 'showAlways' =>
false,
392 'enableTime' =>
false,
399 $fields = $this->fillUfEntityFields($fields);
406 $result = $this->getUfComponentFieldsParent();
414 $this->createUfUrl = $url;
423 $tableClass = StoreDocumentTableManager::getTableClassByType($this->
getDocumentType());
427 return $tableClass::getUfId();
443 return Loc::getMessage(
'CATALOG_STORE_DOCUMENT_DETAIL_TITLE_DEFAULT_NAME_'
451 foreach ($fields as $field)
453 $fieldName = $field[
'name'];
454 $fieldType = $field[
'type'];
456 if ($fieldType ===
'user')
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,
467 $resultFields[] = $field;
470 return $resultFields;
478 'title' =>
Loc::getMessage(
'CATALOG_STORE_DOCUMENT_DETAIL_MAIN_SECTION'),
482 'isRemovable' =>
'false',
488 $sectionElements[] = [
489 'name' =>
'products',
490 'title' =>
Loc::getMessage(
'CATALOG_STORE_DOCUMENT_DETAIL_PRODUCTS_SECTION'),
493 [
'name' =>
'DOCUMENT_PRODUCTS'],
496 'isRemovable' =>
'false',
501 $sectionElements[] = [
503 'title' =>
Loc::getMessage(
'CATALOG_STORE_DOCUMENT_DETAIL_EXTRA_SECTION'),
506 [
'name' =>
'RESPONSIBLE_ID'],
509 'isRemovable' =>
'false',
514 Main\Type\Collection::sortByColumn($sectionElements, [
'sort' => SORT_ASC]);
523 'elements' => $sectionElements,
530 $ufSectionElements = [];
531 $ufInfos = $this->getUfEntityFields();
532 foreach ($ufInfos as $userField)
534 $ufSectionElements[] = [
'name' => $userField[
'name']];
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,
553 [
'name' =>
'TOTAL_WITH_CURRENCY'],
554 ...$ufSectionElements,
559 [
'name' =>
'TOTAL_WITH_CURRENCY'],
560 ...$ufSectionElements,
565 [
'name' =>
'TOTAL_WITH_CURRENCY'],
566 ...$ufSectionElements,
569 return $ufSectionElements;
579 'DOC_TYPE' => $this->document[
'DOC_TYPE'],
580 'RESPONSIBLE_ID' => CurrentUser::get()->getId(),
588 $currency = $this->document[
'CURRENCY'] ??
null;
591 $currency = CurrencyManager::getBaseCurrency();
600 $document[
'FORMATTED_TOTAL'] = CCurrencyLang::CurrencyFormat(
$document[
'TOTAL'], $currency,
false);
601 $document[
'FORMATTED_TOTAL_WITH_CURRENCY'] = CCurrencyLang::CurrencyFormat(
$document[
'TOTAL'],
604 if (empty($this->config[
'skipProducts']))
608 if (empty($this->config[
'skipFiles']))
615 $dateFields = [
'DATE_DOCUMENT',
'ITEMS_ORDER_DATE',
'ITEMS_RECEIVED_DATE'];
616 foreach ($dateFields as $dateField)
639 return array_column($files,
'FILE_ID');
644 $documentProductSummaryInfo = $this->getProductSummaryInfo(
$document);
645 $documentProductSummaryInfo[
'isReadOnly'] = $this->
isReadOnly();
647 return $documentProductSummaryInfo;
650 private function getProductSummaryInfo(array
$document): array
652 $isNewDocument =
$document[
'ID'] ===
null;
657 'total' => \CCurrencyLang::CurrencyFormat(0,
$document[
'CURRENCY']),
667 $productPositionList = $storeDocumentProductPositionRepository->getList(
$document[
'ID']);
668 foreach ($productPositionList as &$productPosition)
670 $productPosition[
'SUM'] = \CCurrencyLang::CurrencyFormat($productPosition[
'SUM'],
$document[
'CURRENCY']);
674 'count' => $storeDocumentProductPositionRepository->getCount(
$document[
'ID']),
680 'items' => $productPositionList,
690 $fieldName = $field[
'name'];
691 $fieldType = $field[
'type'];
693 if ($fieldType ===
'user')
695 $userId =
$document[$field[
'name']] ??
null;
696 if (!$userId && $fieldName ===
'CREATED_BY')
698 $userId = CurrentUser::get()->getId();
701 $userFields[$fieldName] = $userId;
705 $document[
'PATH_TO_USER_PROFILE'] = static::PATH_TO_USER_PROFILE;
712 $uniqueUserIds = array_filter(array_unique(array_values($userFields)));
713 if (!empty($uniqueUserIds) && empty($this->config[
'skipUsers']))
717 elseif(!empty($uniqueUserIds) && !empty(
$document[
'USER_INFO']))
731 'name' =>
'CONTRACTOR_ID',
732 'title' => static::getFieldTitle(
'CONTRACTOR_ID'),
733 'type' => $this->contractorsProvider
734 ? $this->contractorsProvider::getEditorFieldType()
738 'data' => $this->contractorsProvider
739 ? $this->contractorsProvider::getEditorFieldData()
741 'contractorName' =>
'CONTRACTOR_NAME',
752 return $this->contractorsProvider
753 ? $this->contractorsProvider::getEditorEntityData((
int)
$document[
'ID'])
762 if (!empty($this->document[
'CONTRACTOR_REF_COMPANY']))
764 return $this->document[
'CONTRACTOR_REF_COMPANY'];
767 if (!empty($this->document[
'CONTRACTOR_REF_PERSON_NAME']))
769 return $this->document[
'CONTRACTOR_REF_PERSON_NAME'];
777 Main\Type\Collection::normalizeArrayValuesByInt($userIds);
786 foreach ($userIds as $id)
788 if (isset(static::$users[$id]))
790 $usersInfo[$id] = static::$users[$id];
798 if (empty($newUsers))
803 foreach (array_chunk($newUsers, CATALOG_PAGE_SIZE) as $pageIds)
805 $userList = UserTable::getList([
819 while ($user = $userList->fetch())
821 $id = (int)$user[
'ID'];
822 $usersInfo[$id] = $user;
823 static::$users[$id] = $user;
833 foreach ($userFields as $fieldName => $userId)
840 $user = $usersInfo[$userId];
841 $document[
'PATH_TO_' . $fieldName] = \CComponentEngine::MakePathFromTemplate(
842 static::PATH_TO_USER_PROFILE,
843 [
'user_id' => $user[
'ID']]
846 $document[$fieldName .
'_FORMATTED_NAME'] = \CUser::FormatName(
847 \CSite::GetNameFormat(),
849 'ID' => $user[
'ID'] ??
'',
850 'LOGIN' => $user[
'LOGIN'],
851 'NAME' => $user[
'NAME'],
852 'LAST_NAME' => $user[
'LAST_NAME'],
853 'SECOND_NAME' => $user[
'SECOND_NAME'],
859 $personalPhoto = (int)($user[
'PERSONAL_PHOTO'] ?? 0);
860 if ($personalPhoto > 0)
862 $fileInfo = \CFile::ResizeImageGet(
868 BX_RESIZE_IMAGE_EXACT
870 if (isset($fileInfo[
'src']))
872 $document[$fieldName .
'_PHOTO_URL'] = $fileInfo[
'src'];
884 'name' =>
'PRODUCT_LIST_CONTROLLER',
885 'type' =>
'catalog_store_document_product_list',
889 'name' =>
'DOCUMENT_CARD_CONTROLLER',
890 'type' =>
'document_card',
899 $accessController = AccessController::getCurrent();
902 !$accessController->checkByValue(
903 ActionDictionary::ACTION_STORE_DOCUMENT_MODIFY,
907 isset($this->document[
'STATUS']) && $this->document[
'STATUS'] ===
'Y'
915 $accessController = AccessController::getCurrent();
917 return AccessController::getCurrent()->check(ActionDictionary::ACTION_STORE_DOCUMENT_CARD_EDIT);
927 $existingCurrencies = CurrencyTable::getList([
930 'FULL_NAME' =>
'CURRENT_LANG_FORMAT.FULL_NAME',
939 foreach ($existingCurrencies as $currency)
954 'NAME' => $currency[
'FULL_NAME'],
955 'VALUE' => $currency[
'CURRENCY'],
967 case 'TOTAL_WITH_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');
978 return Loc::getMessage(
'CATALOG_STORE_DOCUMENT_DETAIL_FIELD_' . $fieldName);
const TYPE_STORE_ADJUSTMENT
getDocumentCommonFields()
getDocumentFiles(array $document)
getContractorData(array $document)
getUsersInfo(array $userIds)
getAdditionalFieldKeys($fields)
prepareCurrencyListItem(array $currency)
const PATH_TO_USER_PROFILE
getAdditionalDocumentData(array $document)
getTotalInfoControlForExistingDocument()
static getFieldTitle($fieldName)
setCreateUfUrl(string $url)
getDefaultDocumentTitle(string $documentNumber='')
static createById(int $id, array $config=[])
shouldPrepareDateFields()
getAdditionalUserData(array $document, array $userFields, array $usersInfo)
getDocumentSpecificFields()
getTotalInfoControlForNewDocument()
__construct(array $documentFields, array $config=[])
static createByArray(array $documentFields, array $config=[])
static createByType(string $type, array $config=[])
Contractor Provider IProvider $contractorsProvider
getDocumentProductsPreview(array $document)
static getMessage($code, $replace=null, $language=null)
static getRow(array $parameters)
static getList(array $parameters=array())