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();
36 self::$redefinedFields = array_replace_recursive(self::$redefinedFields,
$fields);
46 public static function get($codeKey, $consumerKey =
null, $personTypeId =
null, $providerInstance =
null)
53 $personTypeId =
$provider->getPersonTypeId();
60 'PROPERTY' =>
'BY_ID',
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 = mb_strtoupper($codeKey);
116 return isset(self::$consumerCodePersonMapping[$consumerKey][$codeKey][$personTypeId]);
134 $codeKeyUp = mb_strtoupper($codeKey);
136 if ((
int)$personTypeId === 0)
138 $personTypeId =
null;
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 = mb_strtoupper($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);
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)
354 'select' =>
array(
'CODE_KEY',
'CONSUMER_KEY',
'PERSON_TYPE_ID',
'PROVIDER_KEY',
'PROVIDER_VALUE'),
359 while ($row =
$result->fetch())
361 $row[
'CODE_KEY'] = mb_strtoupper($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)
393 if (isset($providers[$providerKey]))
402 self::sortArray($providers);
406 private static $commonConsumer =
array();
414 if (! self::$consumers)
416 self::$commonConsumer =
array(
417 'NAME' => Loc::getMessage(
'BIZVAL_CONSUMER_COMMON'),
422 self::$consumers[
''] =& self::$commonConsumer;
424 foreach (EventManager::getInstance()->findEventHandlers(
'sale',
'OnGetBusinessValueConsumers') as $handler)
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]);
590 foreach (EventManager::getInstance()->findEventHandlers(
'sale',
'OnGetBusinessValueGroups') as $handler)
596 foreach (
$result as $groupKey => $group)
598 if ($groupKey && is_array($group) && !isset(
$groups[$groupKey]))
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);
629 static $allPersonTypes =
array(), $personTypes =
array();
631 if ($resetAllPersonTypes !==
null)
633 $allPersonTypes = $resetAllPersonTypes;
634 $personTypes = array_filter(
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']);
671 $result[$row[
'ID']][
'PT_SITE'][] = $row[
'PT_SITE'];
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);
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']])
792 && \is_callable(
$provider[
'GET_INSTANCE_VALUE'])
793 && ($v = \call_user_func(
$provider[
'GET_INSTANCE_VALUE'], $providerInstance, $mapping[
'PROVIDER_VALUE'], $personTypeId))
819 public static function getProviders()
821 static $providers =
array();
827 'NAME' => Loc::getMessage(
'BIZVAL_PROVIDER_VALUE'),
831 'NAME' => Loc::getMessage(
'BIZVAL_PROVIDER_COMPANY'),
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' )),
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_')
873 elseif ($company =
Internals\CompanyTable::getById($providerInstance)->fetch())
875 $value = $company[$providerValue];
881 'ORDER' => call_user_func(
885 'NAME' => Loc::getMessage(
'BIZVAL_PROVIDER_ORDER'),
888 'ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_ORDER_ID')),
889 'LID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SITE_ID')),
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')),
896 'USER_ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_USER_ID')),
897 'PAYED' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAID')),
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);
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')];
945 'NAME' => Loc::getMessage(
'BIZVAL_PROVIDER_USER'),
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)
992 $user = \CUser::GetByID($providerInstance)->Fetch();
998 return $user[$providerValue] ??
null;
1002 'NAME' => Loc::getMessage(
'BIZVAL_PROVIDER_PAYMENT'),
1005 'ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_ID')),
1006 'ACCOUNT_NUMBER' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_ACCOUNT_NUMBER')),
1007 'PAID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAID')),
1008 'DATE_PAID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_DATE_PAID')),
1009 'PAY_SYSTEM_ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_SYSTEM_ID')),
1010 'PAY_VOUCHER_NUM' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_VOUCHER_NUM')),
1011 'PAY_VOUCHER_DATE' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_VOUCHER_DATE')),
1012 'DATE_PAY_BEFORE' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_DATE_PAY_BEFORE')),
1013 'DATE_BILL' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_DATE_BILL')),
1014 'DATE_BILL_DATE' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_DATE_BILL_DATE')),
1015 'XML_ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_XML_ID')),
1016 'SUM' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_SUM')),
1017 'CURRENCY' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_CURRENCY')),
1018 'PAY_SYSTEM_NAME' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_SYSTEM_NAME')),
1019 'COMPANY_ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_COMPANY_ID')),
1020 'PAY_RETURN_NUM' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_RETURN_NUM')),
1021 'PAY_RETURN_DATE' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_RETURN_DATE')),
1022 'PAY_RETURN_COMMENT' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_PAYMENT_PAY_RETURN_COMMENT')),
1024 'GET_INSTANCE_VALUE' =>
function ($providerInstance, $providerValue, $personTypeId)
1028 if ($providerInstance instanceof
Payment)
1030 if ($providerValue ==
'DATE_BILL_DATE')
1031 $value =
new Date($providerInstance->getField(
'DATE_BILL'));
1033 $value = $providerInstance->getField($providerValue);
1038 'SHIPMENT' =>
array(
1039 'NAME' => Loc::getMessage(
'BIZVAL_PROVIDER_SHIPMENT'),
1042 'STATUS_ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_STATUS_ID')),
1043 'PRICE_DELIVERY' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_PRICE_DELIVERY')),
1044 'ALLOW_DELIVERY' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_ALLOW_DELIVERY')),
1045 'DATE_ALLOW_DELIVERY' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DATE_ALLOW_DELIVERY')),
1046 'EMP_ALLOW_DELIVERY_ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_EMP_ALLOW_DELIVERY_ID')),
1047 'DEDUCTED' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DEDUCTED')),
1048 'DATE_DEDUCTED' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DATE_DEDUCTED')),
1049 'EMP_DEDUCTED_ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_EMP_DEDUCTED_ID')),
1050 'REASON_UNDO_DEDUCTED' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_REASON_UNDO_DEDUCTED')),
1051 'DELIVERY_ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DELIVERY_ID')),
1052 'DELIVERY_DOC_NUM' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DELIVERY_DOC_NUM')),
1053 'DELIVERY_DOC_DATE' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DELIVERY_DOC_DATE')),
1054 'TRACKING_NUMBER' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_TRACKING_NUMBER')),
1055 'XML_ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_XML_ID')),
1056 'PARAMETERS' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_PARAMETERS')),
1057 'DELIVERY_NAME' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DELIVERY_NAME')),
1058 'COMPANY_ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_COMPANY_ID')),
1059 'MARKED' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_MARKED')),
1060 'DATE_MARKED' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DATE_MARKED')),
1061 'EMP_MARKED_ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_EMP_MARKED_ID')),
1062 'REASON_MARKED' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_REASON_MARKED')),
1063 'CANCELED' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_CANCELED')),
1064 'DATE_CANCELED' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_DATE_CANCELED')),
1065 'EMP_CANCELED_ID' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_CODE_SHIPMENT_EMP_CANCELED_ID')),
1067 'GET_INSTANCE_VALUE' =>
function ($providerInstance, $providerValue, $personTypeId)
1071 if ($providerInstance instanceof
Shipment)
1072 $value = $providerInstance->getField($providerValue);
1077 'PROPERTY' => call_user_func(
1080 $getFields =
function ($registryType)
1084 if (isset(
$fields[$registryType]))
1086 return $fields[$registryType];
1092 'select' =>
array(
'ID',
'NAME',
'PERSON_TYPE_ID',
'TYPE',
'CODE'),
1095 '=ENTITY_REGISTRY_TYPE' => $registryType
1097 'order' =>
array(
'PERSON_TYPE_ID',
'SORT'),
1100 while ($row =
$result->fetch())
1103 $name = $row[
'NAME'];
1106 'CODE' => $row[
'CODE'],
1107 'GROUP' => $row[
'PERSON_TYPE_ID'],
1108 'PERSON_TYPE_ID' => $row[
'PERSON_TYPE_ID']
1111 $fields[$registryType][$id] = $field;
1113 if ($row[
'TYPE'] ==
'LOCATION')
1115 $field[
'NAME'] =
$name.
' ('.Loc::getMessage(
'BIZVAL_CODE_COUNTRY').
')';
1116 $fields[$registryType][$id.
'_COUNTRY'] = $field;
1118 $field[
'NAME'] =
$name.
' ('.Loc::getMessage(
'BIZVAL_CODE_REGION').
')';
1119 $fields[$registryType][$id.
'_REGION'] = $field;
1121 $field[
'NAME'] =
$name.
' ('.Loc::getMessage(
'BIZVAL_CODE_CITY').
')';
1122 $fields[$registryType][$id.
'_CITY'] = $field;
1126 return $fields[$registryType];
1129 $parseId =
function ($propertyId)
1131 $propertyCode =
null;
1132 $locationField =
null;
1134 if (! is_numeric($propertyId))
1136 if ((
$a = explode(
'_', $propertyId, 2))
1137 && is_numeric(
$a[0])
1138 && in_array(
$a[1],
array(
'CITY',
'COUNTRY',
'REGION'),
true))
1140 $propertyId =
$a[0];
1141 $locationField =
$a[1];
1145 $propertyCode = $propertyId;
1150 return array($propertyCode, $propertyId, $locationField);
1154 'NAME' => Loc::getMessage(
'BIZVAL_PROVIDER_PROPERTY'),
1157 'FIELDS_GROUPS' => array_map(
1160 return array(
'NAME' =>
$i[
'TITLE']);
1164 'GET_VALUE' =>
function ($providerValue, $personTypeId,
$options,
$provider) use ($parseId, $getFields)
1166 list ($propertyCode, $propertyId, $locationField) = call_user_func($parseId, $providerValue);
1171 $registry = $provider::getRegistryType();
1178 $fields = $getFields($registry);
1184 foreach (
$fields as $propertyId => $property)
1186 if ($property[
'PERSON_TYPE_ID'] == $personTypeId && $property[
'CODE'] == $propertyCode)
1188 $providerValue = $propertyId;
1198 $providerValue = $property[
'CODE'];
1202 return $providerValue;
1204 'GET_INSTANCE_VALUE' =>
function ($providerInstance, $providerValue, $personTypeId) use ($parseId)
1208 if ($providerInstance instanceof Order)
1210 list ($propertyCode, $propertyId, $locationField) = call_user_func($parseId, $providerValue);
1213 foreach ($providerInstance->getPropertyCollection() as $property)
1215 if ($property->getPersonTypeId() == $personTypeId)
1219 if ($property->getField(
'CODE') == $propertyCode)
1221 $value = $property->getValue();
1225 elseif ($property->getPropertyId() == $propertyId)
1227 if (($value = $property->getValue())
1228 && ($propertyField = $property->getProperty())
1231 if($propertyField[
'TYPE'] ==
"LOCATION")
1235 $filter[
'=PARENTS.NAME.LANGUAGE_ID'] = LANGUAGE_ID;
1236 if(
is_set($locationField))
1238 $filter[
'=PARENTS.TYPE.CODE'] = $locationField;
1241 $row = \Bitrix\Sale\Location\LocationTable::getList(
array(
1242 'select' =>
array(
'LOCATION_NAME' =>
'PARENTS.NAME.NAME'),
1246 $locations =
array();
1248 $locations[] =
$location[
'LOCATION_NAME'];
1250 $value = (
count($locations) > 0) ? implode(
'-', $locations) :
null;
1252 elseif($propertyField[
'TYPE'] ==
"ENUM")
1254 $multipleValues = $property->getValue();
1256 if(is_array($multipleValues) &&
count($multipleValues)>0)
1259 foreach($multipleValues as $v)
1261 if(isset($propertyField[
'OPTIONS'][$v]))
1262 $value[] = $propertyField[
'OPTIONS'][$v];
1266 $value = $propertyField[
'OPTIONS'][$property->getValue()];
1341 'CONSUMER_PAYSYS' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_GROUP_CONSUMER_PAYSYS'),
'SORT' => 100),
1342 'CODE_PAYSYS' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_GROUP_CONSUMER_PAYSYS'),
'SORT' => 100),
1343 'BUYER_PERSON' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_GROUP_BUYER_PERSON'),
'SORT' => 300),
1344 'BUYER_PERSON_COMPANY' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_GROUP_BUYER_PERSON_COMPANY'),
'SORT' => 305),
1345 'BUYER_COMPANY' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_GROUP_BUYER_COMPANY'),
'SORT' => 310),
1346 '1C_REKV' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_GROUP_1C_REKV'),
'SORT' => 320),
1347 'SELLER_PERSON' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_GROUP_SELLER_PERSON'),
'SORT' => 400),
1348 'SELLER_PERSON_COMPANY' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_GROUP_SELLER_PERSON_COMPANY'),
'SORT' => 405),
1349 'SELLER_COMPANY' =>
array(
'NAME' => Loc::getMessage(
'BIZVAL_GROUP_SELLER_PERSON'),
'SORT' => 410),
static getList(array $parameters=array())
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)