19 private const EVENT_ON_BUSINESS_VALUE_SET_MAPPING =
'OnBusinessValueSetMapping';
21 private static $redefinedFields = array();
22 private static $consumers = array();
23 private static $consumerCodePersonMapping = array();
28 return self::get($codeKey, $consumerKey, $provider);
36 self::$redefinedFields = array_replace_recursive(self::$redefinedFields, $fields);
46 public static function get($codeKey, $consumerKey =
null, $personTypeId =
null, $providerInstance =
null)
52 $provider = $personTypeId;
53 $personTypeId = $provider->getPersonTypeId();
60 'PROPERTY' =>
'BY_ID',
61 'PROVIDER' => $provider,
66 $providerInstance = $provider->getBusinessValueProviderInstance($mapping);
70 if ($personTypeId <= 0)
80 'PROPERTY' =>
'BY_ID',
87 isset($mapping[
'PROVIDER_VALUE'])
88 && isset($mapping[
'PROVIDER_KEY'])
89 && isset(self::$redefinedFields[$mapping[
'PROVIDER_KEY']][$mapping[
'PROVIDER_VALUE']]))
91 return self::$redefinedFields[$mapping[
'PROVIDER_KEY']][$mapping[
'PROVIDER_VALUE']];
95 isset($mapping[
'PROVIDER_KEY'])
96 && $mapping[
'PROVIDER_KEY']
97 && isset($mapping[
'PROVIDER_VALUE'])
98 && $mapping[
'PROVIDER_VALUE']
101 $value = self::getValueFromMapping($mapping, $providerInstance, $personTypeId);
113 public static function isSetMapping($codeKey, $consumerKey =
null, $personTypeId =
null)
115 $codeKey = ToUpper($codeKey);
116 return isset(self::$consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId]);
131 public static function getMapping($codeKey, $consumerKey =
null, $personTypeId =
null, array $options = array())
134 $codeKeyUp = ToUpper($codeKey);
136 if ((
int)$personTypeId === 0)
138 $personTypeId =
null;
141 $match = isset($options[
'MATCH']) && is_int($options[
'MATCH']) ? $options[
'MATCH'] :
self::MATCH_ALL;
143 $consumerCodePersonMapping =
144 isset($options[
'consumerCodePersonMapping']) && is_array($options[
'consumerCodePersonMapping'])
145 ? $options[
'consumerCodePersonMapping']
149 if ($match & self::MATCH_EXACT && isset($consumerCodePersonMapping[$consumerKey][$codeKeyUp][$personTypeId]))
151 $mapping = $consumerCodePersonMapping[$consumerKey][$codeKeyUp][$personTypeId];
155 if ($match & self::MATCH_COMMON)
157 if ($personTypeId && isset($consumerCodePersonMapping[$consumerKey][$codeKeyUp][
'']))
158 $mapping = $consumerCodePersonMapping[$consumerKey][$codeKeyUp][
''];
159 elseif ($consumerKey && isset($consumerCodePersonMapping[
''][$codeKeyUp][$personTypeId]))
160 $mapping = $consumerCodePersonMapping[
''][$codeKeyUp][$personTypeId];
161 elseif ($consumerKey && $personTypeId && isset($consumerCodePersonMapping[
''][$codeKeyUp][
'']))
162 $mapping = $consumerCodePersonMapping[
''][$codeKeyUp][
''];
165 if (! $mapping && $match & self::MATCH_DEFAULT && ($consumers = self::getConsumers()))
167 $mappingValue = $consumers[$consumerKey][
'CODES'][$codeKey][
'DEFAULT'] ??
null;
168 if (is_array($mappingValue))
170 $mapping = $mappingValue;
181 && $mapping[
'PROVIDER_KEY'] ==
'PROPERTY'
182 && $mapping[
'PROVIDER_VALUE']
184 && is_callable($providers[
'PROPERTY'][
'GET_VALUE']))
186 $mapping[
'PROVIDER_VALUE'] = call_user_func($providers[
'PROPERTY'][
'GET_VALUE'],
187 $mapping[
'PROVIDER_VALUE'],
189 $options[
'GET_VALUE'][
'PROPERTY'] ??
null,
190 $options[
'GET_VALUE'][
'PROVIDER'] ??
null
206 public static function setMapping($codeKey, $consumerKey, $personTypeId, array $mapping, $withCommon =
false)
208 $codeKey = ToUpper($codeKey);
210 $oldMapping =
self::getMapping($codeKey, $consumerKey, $personTypeId, [
'MATCH' => self::MATCH_EXACT]);
212 if (! $consumerKey || $consumerKey === BusinessValueTable::COMMON_CONSUMER_KEY)
215 if (! $personTypeId || $personTypeId === BusinessValueTable::COMMON_PERSON_TYPE_ID)
216 $personTypeId =
null;
218 if (!array_key_exists(
'PROVIDER_KEY', $mapping) || !array_key_exists(
'PROVIDER_VALUE', $mapping))
222 'CODE_KEY' => $codeKey,
224 'CONSUMER_KEY' => $consumerKey ?: BusinessValueTable::COMMON_CONSUMER_KEY,
225 'PERSON_TYPE_ID' => $personTypeId ?: BusinessValueTable::COMMON_PERSON_TYPE_ID,
230 if (isset($consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId]))
234 $savedMapping = $consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId];
236 if (! ($mapping[
'PROVIDER_KEY'] == $savedMapping[
'PROVIDER_KEY']
237 && $mapping[
'PROVIDER_VALUE'] == $savedMapping[
'PROVIDER_VALUE']))
238 $result = BusinessValueTable::update($primary, $mapping);
242 $result = BusinessValueTable::delete($primary);
249 && !isset($consumerCodePersonMapping[
''][$codeKey][
''])
253 $personTypeId =
null;
254 $primary[
'CONSUMER_KEY'] = BusinessValueTable::COMMON_CONSUMER_KEY;
255 $primary[
'PERSON_TYPE_ID'] = BusinessValueTable::COMMON_PERSON_TYPE_ID;
258 $result = BusinessValueTable::add($primary + $mapping);
263 if ($result->isSuccess())
267 self::$consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId] = $mapping;
271 unset(self::$consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId]);
275 'CODE_KEY' => $codeKey,
276 'CONSUMER_KEY' => $consumerKey,
277 'PERSON_TYPE_ID' => $personTypeId,
278 'OLD_MAPPING' => $oldMapping,
279 'NEW_MAPPING' => $mapping,
281 $onSetMappingEvent =
new Event(
'sale', self::EVENT_ON_BUSINESS_VALUE_SET_MAPPING, $eventParams);
282 EventManager::getInstance()->send($onSetMappingEvent);
287 $result = new \Bitrix\Main\Entity\Result;
298 public static function delete($consumerKey, $personTypeId =
null)
301 if (!isset($consumerCodePersonMapping[$consumerKey]))
306 foreach ($consumerCodePersonMapping[$consumerKey] as $code => $personTypes)
308 if ($personTypeId ===
null)
310 foreach ($personTypes as $id => $mapping)
312 self::deleteInternal($consumerKey, $code, $id, $mapping);
317 $mapping = $personTypes[$personTypeId];
318 self::deleteInternal($consumerKey, $code, $personTypeId, $mapping);
330 private static function deleteInternal($consumerKey, $code, $personTypeId, $mapping)
332 $consumers = static::getConsumers();
334 if ($mapping[
'PROVIDER_KEY'] ===
'INPUT'
335 && $consumers[$consumerKey][
'CODES'][$code][
'INPUT'][
'TYPE'] ===
'FILE'
338 \CFile::Delete($mapping[
'PROVIDER_VALUE']);
341 BusinessValueTable::delete([
342 'CONSUMER_KEY' => $consumerKey,
344 'PERSON_TYPE_ID' => $personTypeId,
351 if (! self::$consumerCodePersonMapping)
353 $result = BusinessValueTable::getList(array(
354 'select' => array(
'CODE_KEY',
'CONSUMER_KEY',
'PERSON_TYPE_ID',
'PROVIDER_KEY',
'PROVIDER_VALUE'),
359 while ($row = $result->fetch())
361 $row[
'CODE_KEY'] = ToUpper($row[
'CODE_KEY']);
364 self::$consumerCodePersonMapping[$row[
'CONSUMER_KEY']][$row[
'CODE_KEY']][$row[
'PERSON_TYPE_ID']] = array(
365 'PROVIDER_KEY' => $row[
'PROVIDER_KEY'],
366 'PROVIDER_VALUE' => $row[
'PROVIDER_VALUE'],
371 return self::$consumerCodePersonMapping;
381 $providers = BusinessValueHandlers::getProviders();
383 foreach (EventManager::getInstance()->findEventHandlers(
'sale',
'OnGetBusinessValueProviders') as $handler)
385 $result = ExecuteModuleEventEx($handler);
387 if (is_array($result))
389 foreach ($result as $providerKey => $provider)
391 if ($providerKey && is_array($provider))
393 if (isset($providers[$providerKey]))
396 $providers[$providerKey] = $provider;
402 self::sortArray($providers);
406 private static $commonConsumer = array();
414 if (! self::$consumers)
416 self::$commonConsumer = array(
422 self::$consumers[
''] =& self::$commonConsumer;
424 foreach (EventManager::getInstance()->findEventHandlers(
'sale',
'OnGetBusinessValueConsumers') as $handler)
426 $result = ExecuteModuleEventEx($handler);
428 if (is_array($result))
430 foreach ($result as $consumerKey => &$consumer)
432 if ($consumerKey && is_array($consumer))
434 self::addConsumerByRef($consumerKey, $consumer);
439 self::sortArray(self::$commonConsumer[
'CODES']);
441 self::sortArray(self::$consumers);
451 return self::$consumers;
454 private static function addConsumerByRef($consumerKey, array &$consumer)
456 if (isset(self::$consumers[$consumerKey]) || $consumerKey == BusinessValueTable::COMMON_CONSUMER_KEY)
463 if (isset($consumer[
'CODES']) && is_array($consumer[
'CODES']))
465 $codes =& self::$commonConsumer[
'CODES'];
467 foreach ($consumer[
'CODES'] as $codeKey => $code)
469 $isCommon = !($code[
'NOT_COMMON'] ??
false);
470 if ($codeKey && is_array($code) && $isCommon)
472 $codeName = ($code[
'NAME'] ??
null) ?: $codeKey;
474 if ($c =& $codes[$codeKey])
476 if (empty($c[
'GROUP']) && !empty($code[
'GROUP']))
478 $c[
'GROUP'] = $code[
'GROUP'];
481 if (!isset($c[
'SORT']) && isset($code[
'SORT']))
483 $c[
'SORT'] = $code[
'SORT'];
487 isset($c[
'DEFAULT'], $code[
'DEFAULT'])
488 && !is_array($c[
'DEFAULT'])
489 && is_array($code[
'DEFAULT'])
492 $c[
'DEFAULT'] = $code[
'DEFAULT'];
495 if (isset($code[
'DOMAINS']) && is_array($code[
'DOMAINS']))
497 $c[
'DOMAINS'] = isset($c[
'DOMAINS']) && is_array($c[
'DOMAINS'])
498 ? array_intersect($c[
'DOMAINS'], $code[
'DOMAINS'])
503 if (!isset($code[
'PROVIDERS']) || !is_array($code[
'PROVIDERS']))
505 $code[
'PROVIDERS'] = $consumer[
'PROVIDERS'] ?? [];
508 if (is_array($code[
'PROVIDERS']))
510 $c[
'PROVIDERS'] = isset($c[
'PROVIDERS']) && is_array($c[
'PROVIDERS'])
511 ? array_intersect($c[
'PROVIDERS'], $code[
'PROVIDERS'])
516 $c[
'NAMES'][$codeName] = 1;
524 $c[
'PROVIDERS'] = $code[
'PROVIDERS'] ?? $consumer[
'PROVIDERS'] ?? [];
525 $c[
'NAMES'][$codeName] = 1;
528 $c[
'CONSUMERS'] []= !empty($consumer[
'NAME']) ? $consumer[
'NAME'] : $consumerKey;
532 self::sortArray($consumer[
'CODES']);
535 self::$consumers[$consumerKey] = & $consumer;
543 if (! is_array($consumer))
547 self::addConsumerByRef($consumerKey, $consumer);
557 if (! isset(self::$consumers[$consumerKey]))
558 throw new SystemException(
'There is no consumer "'.$consumerKey.
'" to change!');
560 self::$consumers[$consumerKey] = $consumer;
565 if (! ($fromConsumerKey && $toConsumerKey))
568 if ($fromConsumerKey == $toConsumerKey)
573 if (! isset(self::$consumers[$fromConsumerKey]))
574 throw new SystemException(
'There is no consumer "'.$fromConsumerKey.
'" to change key!');
576 if (isset(self::$consumers[$toConsumerKey]))
577 throw new SystemException(
'Cannot change to consumer key "'.$toConsumerKey.
'", as it already exists!');
580 self::$consumers[$toConsumerKey] = & self::$consumers[$fromConsumerKey];
581 unset(self::$consumers[$fromConsumerKey]);
586 static $groups = array();
590 foreach (EventManager::getInstance()->findEventHandlers(
'sale',
'OnGetBusinessValueGroups') as $handler)
592 $result = ExecuteModuleEventEx($handler);
594 if (is_array($result))
596 foreach ($result as $groupKey => $group)
598 if ($groupKey && is_array($group) && !isset($groups[$groupKey]))
600 $groups[$groupKey] = $group;
606 self::sortArray($groups);
613 private static function sortArray(array &$data)
619 $a = is_array($aa) ? (int)($aa[
'SORT'] ?? 0) : 0;
620 $b = is_array($bb) ? (int)($bb[
'SORT'] ?? 0) : 0;
621 return $a < $b ? -1 : ($a > $b ? 1 : 0);
627 public static function getPersonTypes($all =
false, array $resetAllPersonTypes =
null)
629 static $allPersonTypes = array(), $personTypes = array();
631 if ($resetAllPersonTypes !==
null)
633 $allPersonTypes = $resetAllPersonTypes;
634 $personTypes = array_filter(
642 elseif (!$allPersonTypes)
644 $dbRes = Internals\PersonTypeTable::getList([
646 'ID',
'NAME',
'LID',
'ACTIVE',
'ENTITY_REGISTRY_TYPE',
647 'DOMAIN' =>
'BIZVAL.DOMAIN',
648 'PT_SITE' =>
'PERSON_TYPE_SITE.SITE_ID'
650 'order' => [
'SORT',
'NAME'],
654 'Bitrix\Sale\Internals\BusinessValuePersonDomainTable',
655 [
'=this.ID' =>
'ref.PERSON_TYPE_ID'],
656 [
'join_type' =>
'LEFT']
662 while ($row = $dbRes->fetch())
664 if (!isset($result[$row[
'ID']]))
666 $row[
'PT_SITE'] = array($row[
'PT_SITE']);
667 $result[$row[
'ID']] = $row;
671 $result[$row[
'ID']][
'PT_SITE'][] = $row[
'PT_SITE'];
675 foreach ($result as $item)
677 $item[
'TITLE'] = $item[
'NAME'].
' ('.implode(
', ' , $item[
'PT_SITE']).
')';
679 $allPersonTypes[$item[
'ID']] = $item;
682 $personTypes[$item[
'ID']] = $item;
686 return $all ? $allPersonTypes : $personTypes;
702 if (!isset($oldMapping[
'PROVIDER_KEY'], $oldMapping[
'PROVIDER_VALUE']))
704 throw new \Bitrix\Main\ArgumentException(
"Parameters \$oldMapping['PROVIDER_KEY'] and \$oldMapping['PROVIDER_VALUE'] are required.",
'oldMapping');
707 $result = new \Bitrix\Main\Entity\Result();
710 'CODE_KEY' => $codeKey,
711 'PROVIDER_KEY' => $oldMapping[
'PROVIDER_KEY'],
712 'PROVIDER_VALUE' => $oldMapping[
'PROVIDER_VALUE'],
717 $filter[
'CONSUMER_KEY'] = $consumerKey;
722 $filter[
'PERSON_TYPE_ID'] = $personTypeId;
725 $businessValueResult = BusinessValueTable::getList(array(
726 'select' => [
'CONSUMER_KEY',
'PERSON_TYPE_ID'],
730 while ($item = $businessValueResult->fetch())
732 $setMappingResult =
self::setMapping($codeKey, $item[
'CONSUMER_KEY'], $item[
'PERSON_TYPE_ID'], $newMapping);
733 if (!$setMappingResult->isSuccess())
735 $result->addErrors($setMappingResult->getErrors());
752 if (isset($consumerCodePersonMapping[
''][$code]))
754 $consumerValues = $consumerCodePersonMapping[
''][$code];
755 foreach ($consumerValues as $values)
757 if ($values[
'PROVIDER_KEY'] && $values[
'PROVIDER_VALUE'])
759 $result[] = self::getValueFromMapping($values);
764 $consumerValues = $consumerCodePersonMapping[$consumerName][$code] ?? [];
765 foreach ($consumerValues as $values)
767 if ($values[
'PROVIDER_KEY'] && $values[
'PROVIDER_VALUE'])
769 $result[] = self::getValueFromMapping($values);
773 return array_unique($result);
776 private static function getValueFromMapping(array $mapping, $providerInstance =
null, $personTypeId =
null)
780 switch ($mapping[
'PROVIDER_KEY'])
784 $value = $mapping[
'PROVIDER_VALUE'];
789 ($providers = self::getProviders())
790 && ($provider = $providers[$mapping[
'PROVIDER_KEY']])
791 && \is_array($provider)
792 && \is_callable($provider[
'GET_INSTANCE_VALUE'])
793 && ($v = \call_user_func($provider[
'GET_INSTANCE_VALUE'], $providerInstance, $mapping[
'PROVIDER_VALUE'], $personTypeId))
806 public static function install($parentName, $translationSource, $data)
819 public static function getProviders()
821 static $providers = array();
833 'FIELDS' => call_user_func(
function ()
836 'ID' => array(
'GROUP' =>
'ENTITY',
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_COMPANY_ID')),
837 'NAME' => array(
'GROUP' =>
'ENTITY',
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_NAME' )),
838 'LOCATION_ID' => array(
'GROUP' =>
'ENTITY',
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_LOCATION' )),
839 'CODE' => array(
'GROUP' =>
'ENTITY',
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_CODE' )),
840 'XML_ID' => array(
'GROUP' =>
'ENTITY',
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_XML_ID' )),
841 'ACTIVE' => array(
'GROUP' =>
'ENTITY',
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ACTIVE' )),
842 'DATE_CREATE' => array(
'GROUP' =>
'ENTITY',
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_DATE_CREATE')),
843 'DATE_MODIFY' => array(
'GROUP' =>
'ENTITY',
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_DATE_MODIFY')),
844 'CREATED_BY' => array(
'GROUP' =>
'ENTITY',
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_CREATED_BY' )),
845 'MODIFIED_BY' => array(
'GROUP' =>
'ENTITY',
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_MODIFIED_BY')),
846 'ADDRESS' => array(
'GROUP' =>
'ENTITY',
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ADDRESS' )),
849 global $USER_FIELD_MANAGER;
852 foreach ($result as $name => $row)
853 $data[$name] = array(
'NAME' => $row[
'EDIT_FORM_LABEL'] ?: $name,
'GROUP' =>
'UF');
857 'FIELDS_GROUPS' => array(
858 'ENTITY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_GROUP_CODE_COMPANY_ENTITY')),
859 'UF' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_GROUP_CODE_COMPANY_UF' )),
861 'GET_INSTANCE_VALUE' =>
function ($providerInstance, $providerValue, $personTypeId)
865 if ($providerInstance ===
null)
868 if (mb_substr($providerValue, 0, 3) ==
'UF_')
870 global $USER_FIELD_MANAGER;
871 $value = $USER_FIELD_MANAGER->GetUserFieldValue(Internals\
CompanyTable::getUfId(), $providerValue, $providerInstance) ?:
null;
873 elseif ($company = Internals\CompanyTable::getById($providerInstance)->fetch())
875 $value = $company[$providerValue];
881 'ORDER' => call_user_func(
890 'ACCOUNT_NUMBER' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_ACCOUNT_NUMBER')),
891 'TRACKING_NUMBER' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_TRACKING_NUMBER')),
892 'DATE_INSERT' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_DATE_CREATE')),
893 'DATE_INSERT_DATE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_DATE_CREATE_DATE')),
894 'DATE_UPDATE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_DATE_MODIFY')),
895 'PERSON_TYPE_ID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PERSON_TYPE_ID')),
898 'DATE_PAY_BEFORE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_PAY_BEFORE')),
899 'SHOULD_PAY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_PRICE')),
900 'CURRENCY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_CURRENCY')),
901 'PRICE_DELIVERY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_PRICE_DELIV')),
902 'DISCOUNT_VALUE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_DESCOUNT')),
903 'PAY_SYSTEM_ID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_PAY_SYSTEM_ID')),
904 'DELIVERY_ID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_DELIVERY_ID')),
905 'TAX_VALUE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_TAX')),
906 'COMMENTS' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_COMMENTS')),
907 'USER_DESCRIPTION' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_USER_DESCRIPTION')),
909 'GET_INSTANCE_VALUE' =>
function ($providerInstance, $providerValue, $personTypeId)
913 if ($providerInstance instanceof
Order)
915 if ($providerValue ==
'DATE_INSERT_DATE')
917 $value =
new Date($providerInstance->getField(
'DATE_INSERT'));
919 else if ($providerValue ==
'DATE_BILL_DATE')
921 $value =
new Date($providerInstance->getField(
'DATE_BILL'));
925 $value = $providerInstance->getField($providerValue);
933 if (IsModuleInstalled(
'crm'))
935 $result[
'FIELDS'][
'ORDER_TOPIC'] = [
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_ORDER_TOPIC')];
936 $result[
'FIELDS'][
'PRICE'] = [
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_PRICE')];
937 $result[
'FIELDS'][
'DATE_BILL'] = [
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_DATE_BILL')];
938 $result[
'FIELDS'][
'DATE_BILL_DATE'] = [
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ORDER_DATE_BILL_DATE')];
948 'ID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_USER_ID'),
'GROUP' =>
'CLIENT'),
949 'LOGIN' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_LOGIN'),
'GROUP' =>
'CLIENT'),
950 'NAME' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_FIRST_NAME'),
'GROUP' =>
'CLIENT'),
951 'SECOND_NAME' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SECOND_NAME'),
'GROUP' =>
'CLIENT'),
952 'LAST_NAME' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_LAST_NAME'),
'GROUP' =>
'CLIENT'),
953 'EMAIL' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_EMAIL'),
'GROUP' =>
'CLIENT'),
954 'LID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SITE_ID'),
'GROUP' =>
'CLIENT'),
955 'PERSONAL_PROFESSION' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_JOB_PROFESSION'),
'GROUP' =>
'CLIENT'),
956 'PERSONAL_WWW' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_WEBSITE'),
'GROUP' =>
'CLIENT'),
957 'PERSONAL_ICQ' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ICQ'),
'GROUP' =>
'CLIENT'),
958 'PERSONAL_GENDER' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_GENDER'),
'GROUP' =>
'CLIENT'),
959 'PERSONAL_FAX' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_FAX'),
'GROUP' =>
'CLIENT'),
960 'PERSONAL_MOBILE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PHONE'),
'GROUP' =>
'CLIENT'),
961 'PERSONAL_STREET' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ADDRESS'),
'GROUP' =>
'CLIENT'),
962 'PERSONAL_MAILBOX' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_POSTAL_ADDRESS'),
'GROUP' =>
'CLIENT'),
963 'PERSONAL_CITY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_CITY'),
'GROUP' =>
'CLIENT'),
964 'PERSONAL_STATE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_REGION'),
'GROUP' =>
'CLIENT'),
965 'PERSONAL_ZIP' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ZIP'),
'GROUP' =>
'CLIENT'),
966 'PERSONAL_COUNTRY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_COUNTRY'),
'GROUP' =>
'CLIENT'),
967 'PERSONAL_NOTES' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_NOTES'),
'GROUP' =>
'CLIENT'),
968 'WORK_COMPANY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_NAME'),
'GROUP' =>
'CLIENT_COMPANY'),
969 'WORK_DEPARTMENT' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_JOB_DEPARTMENT'),
'GROUP' =>
'CLIENT_COMPANY'),
970 'WORK_POSITION' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_JOB_POSITION' ),
'GROUP' =>
'CLIENT_COMPANY'),
971 'WORK_WWW' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_WEBSITE'),
'GROUP' =>
'CLIENT_COMPANY'),
972 'WORK_PHONE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PHONE'),
'GROUP' =>
'CLIENT_COMPANY'),
973 'WORK_FAX' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_FAX'),
'GROUP' =>
'CLIENT_COMPANY'),
974 'WORK_STREET' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ADDRESS'),
'GROUP' =>
'CLIENT_COMPANY'),
975 'WORK_MAILBOX' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_POSTAL_ADDRESS'),
'GROUP' =>
'CLIENT_COMPANY'),
976 'WORK_CITY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_CITY'),
'GROUP' =>
'CLIENT_COMPANY'),
977 'WORK_STATE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_REGION'),
'GROUP' =>
'CLIENT_COMPANY'),
978 'WORK_ZIP' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_ZIP'),
'GROUP' =>
'CLIENT_COMPANY'),
979 'WORK_COUNTRY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_COUNTRY'),
'GROUP' =>
'CLIENT_COMPANY'),
981 'FIELDS_GROUPS' => array(
982 'CLIENT' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_GROUP_CODE_CLIENT' )),
983 'CLIENT_COMPANY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_GROUP_CODE_CLIENT_COMPANY')),
985 'GET_INSTANCE_VALUE' =>
function ($providerInstance, $providerValue, $personTypeId)
991 if ($user = $USER->GetByID($providerInstance)->Fetch())
993 $value = $user[$providerValue];
1003 'ACCOUNT_NUMBER' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_ACCOUNT_NUMBER')),
1004 'PAID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAID')),
1005 'DATE_PAID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_DATE_PAID')),
1006 'PAY_SYSTEM_ID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_SYSTEM_ID')),
1007 'PAY_VOUCHER_NUM' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_VOUCHER_NUM')),
1008 'PAY_VOUCHER_DATE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_VOUCHER_DATE')),
1009 'DATE_PAY_BEFORE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_DATE_PAY_BEFORE')),
1010 'DATE_BILL' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_DATE_BILL')),
1011 'DATE_BILL_DATE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_DATE_BILL_DATE')),
1014 'CURRENCY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_CURRENCY')),
1015 'PAY_SYSTEM_NAME' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_SYSTEM_NAME')),
1016 'COMPANY_ID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_COMPANY_ID')),
1017 'PAY_RETURN_NUM' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_RETURN_NUM')),
1018 'PAY_RETURN_DATE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_RETURN_DATE')),
1019 'PAY_RETURN_COMMENT' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_RETURN_COMMENT')),
1021 'GET_INSTANCE_VALUE' =>
function ($providerInstance, $providerValue, $personTypeId)
1025 if ($providerInstance instanceof
Payment)
1027 if ($providerValue ==
'DATE_BILL_DATE')
1028 $value =
new Date($providerInstance->getField(
'DATE_BILL'));
1030 $value = $providerInstance->getField($providerValue);
1035 'SHIPMENT' => array(
1039 'STATUS_ID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_STATUS_ID')),
1040 'PRICE_DELIVERY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_PRICE_DELIVERY')),
1041 'ALLOW_DELIVERY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_ALLOW_DELIVERY')),
1042 'DATE_ALLOW_DELIVERY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DATE_ALLOW_DELIVERY')),
1043 'EMP_ALLOW_DELIVERY_ID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_EMP_ALLOW_DELIVERY_ID')),
1044 'DEDUCTED' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DEDUCTED')),
1045 'DATE_DEDUCTED' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DATE_DEDUCTED')),
1046 'EMP_DEDUCTED_ID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_EMP_DEDUCTED_ID')),
1047 'REASON_UNDO_DEDUCTED' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_REASON_UNDO_DEDUCTED')),
1048 'DELIVERY_ID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DELIVERY_ID')),
1049 'DELIVERY_DOC_NUM' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DELIVERY_DOC_NUM')),
1050 'DELIVERY_DOC_DATE' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DELIVERY_DOC_DATE')),
1051 'TRACKING_NUMBER' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_TRACKING_NUMBER')),
1053 'PARAMETERS' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_PARAMETERS')),
1054 'DELIVERY_NAME' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DELIVERY_NAME')),
1055 'COMPANY_ID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_COMPANY_ID')),
1056 'MARKED' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_MARKED')),
1057 'DATE_MARKED' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DATE_MARKED')),
1058 'EMP_MARKED_ID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_EMP_MARKED_ID')),
1059 'REASON_MARKED' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_REASON_MARKED')),
1060 'CANCELED' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_CANCELED')),
1061 'DATE_CANCELED' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DATE_CANCELED')),
1062 'EMP_CANCELED_ID' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_EMP_CANCELED_ID')),
1064 'GET_INSTANCE_VALUE' =>
function ($providerInstance, $providerValue, $personTypeId)
1068 if ($providerInstance instanceof
Shipment)
1069 $value = $providerInstance->getField($providerValue);
1074 'PROPERTY' => call_user_func(
1077 $getFields =
function ($registryType)
1079 static $fields = array();
1081 if (isset($fields[$registryType]))
1083 return $fields[$registryType];
1086 $fields[$registryType] = [];
1088 $result = Internals\OrderPropsTable::getList(array(
1089 'select' => array(
'ID',
'NAME',
'PERSON_TYPE_ID',
'TYPE',
'CODE'),
1092 '=ENTITY_REGISTRY_TYPE' => $registryType
1094 'order' => array(
'PERSON_TYPE_ID',
'SORT'),
1097 while ($row = $result->fetch())
1100 $name = $row[
'NAME'];
1103 'CODE' => $row[
'CODE'],
1104 'GROUP' => $row[
'PERSON_TYPE_ID'],
1105 'PERSON_TYPE_ID' => $row[
'PERSON_TYPE_ID']
1108 $fields[$registryType][$id] = $field;
1110 if ($row[
'TYPE'] ==
'LOCATION')
1112 $field[
'NAME'] = $name.
' ('.
Loc::getMessage(
'BIZVAL_CODE_COUNTRY').
')';
1113 $fields[$registryType][$id.
'_COUNTRY'] = $field;
1115 $field[
'NAME'] = $name.
' ('.
Loc::getMessage(
'BIZVAL_CODE_REGION').
')';
1116 $fields[$registryType][$id.
'_REGION'] = $field;
1119 $fields[$registryType][$id.
'_CITY'] = $field;
1123 return $fields[$registryType];
1126 $parseId =
function ($propertyId)
1128 $propertyCode =
null;
1129 $locationField =
null;
1131 if (! is_numeric($propertyId))
1133 if (($a = explode(
'_', $propertyId, 2))
1134 && is_numeric($a[0])
1135 && in_array($a[1], array(
'CITY',
'COUNTRY',
'REGION'),
true))
1137 $propertyId = $a[0];
1138 $locationField = $a[1];
1142 $propertyCode = $propertyId;
1147 return array($propertyCode, $propertyId, $locationField);
1154 'FIELDS_GROUPS' => array_map(
1157 return array(
'NAME' => $i[
'TITLE']);
1161 'GET_VALUE' =>
function ($providerValue, $personTypeId, $options, $provider) use ($parseId, $getFields)
1163 list ($propertyCode, $propertyId, $locationField) = call_user_func($parseId, $providerValue);
1166 if ($provider && method_exists($provider,
'getRegistryType'))
1168 $registry = $provider::getRegistryType();
1175 $fields = $getFields($registry);
1179 if ($options ==
'BY_ID')
1181 foreach ($fields as $propertyId => $property)
1183 if ($property[
'PERSON_TYPE_ID'] == $personTypeId && $property[
'CODE'] == $propertyCode)
1185 $providerValue = $propertyId;
1193 if ($options !=
'BY_ID' && ($property = $fields[$propertyId]))
1195 $providerValue = $property[
'CODE'];
1199 return $providerValue;
1201 'GET_INSTANCE_VALUE' =>
function ($providerInstance, $providerValue, $personTypeId) use ($parseId)
1205 if ($providerInstance instanceof
Order)
1207 list ($propertyCode, $propertyId, $locationField) = call_user_func($parseId, $providerValue);
1210 foreach ($providerInstance->getPropertyCollection() as $property)
1212 if ($property->getPersonTypeId() == $personTypeId)
1216 if ($property->getField(
'CODE') == $propertyCode)
1218 $value = $property->getValue();
1222 elseif ($property->getPropertyId() == $propertyId)
1224 if (($value = $property->getValue())
1225 && ($propertyField = $property->getProperty())
1228 if($propertyField[
'TYPE'] ==
"LOCATION")
1231 $filter[
'=CODE'] = $value;
1232 $filter[
'=PARENTS.NAME.LANGUAGE_ID'] = LANGUAGE_ID;
1233 if(is_set($locationField))
1235 $filter[
'=PARENTS.TYPE.CODE'] = $locationField;
1238 $row = \Bitrix\Sale\Location\LocationTable::getList(array(
1239 'select' => array(
'LOCATION_NAME' =>
'PARENTS.NAME.NAME'),
1240 'filter' => $filter,
1243 $locations = array();
1244 while($location = $row->fetch())
1245 $locations[] = $location[
'LOCATION_NAME'];
1247 $value = (count($locations) > 0) ? implode(
'-', $locations) :
null;
1249 elseif($propertyField[
'TYPE'] ==
"ENUM")
1251 $multipleValues = $property->getValue();
1253 if(is_array($multipleValues) && count($multipleValues)>0)
1256 foreach($multipleValues as $v)
1258 if(isset($propertyField[
'OPTIONS'][$v]))
1259 $value[] = $propertyField[
'OPTIONS'][$v];
1263 $value = $propertyField[
'OPTIONS'][$property->getValue()];
1338 'CONSUMER_PAYSYS' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_GROUP_CONSUMER_PAYSYS'),
'SORT' => 100),
1339 'CODE_PAYSYS' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_GROUP_CONSUMER_PAYSYS'),
'SORT' => 100),
1340 'BUYER_PERSON' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_GROUP_BUYER_PERSON'),
'SORT' => 300),
1341 'BUYER_PERSON_COMPANY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_GROUP_BUYER_PERSON_COMPANY'),
'SORT' => 305),
1342 'BUYER_COMPANY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_GROUP_BUYER_COMPANY'),
'SORT' => 310),
1343 '1C_REKV' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_GROUP_1C_REKV'),
'SORT' => 320),
1344 'SELLER_PERSON' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_GROUP_SELLER_PERSON'),
'SORT' => 400),
1345 'SELLER_PERSON_COMPANY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_GROUP_SELLER_PERSON_COMPANY'),
'SORT' => 405),
1346 'SELLER_COMPANY' => array(
'NAME' =>
Loc::getMessage(
'BIZVAL_GROUP_SELLER_PERSON'),
'SORT' => 410),
static getMessage($code, $replace=null, $language=null)