182 $query = CrmContactTable::query();
184 if ($query->getEntity()->hasField(
'CATEGORY_ID'))
186 $query->where(
'CATEGORY_ID', 0);
189 $query->registerRuntimeField(
new Entity\
ExpressionField(
'CRM_ENTITY_TYPE_ID', \CCrmOwnerType::Contact));
190 $query->registerRuntimeField(
new Entity\
ExpressionField(
'CRM_ENTITY_TYPE',
'\''.\CCrmOwnerType::ContactName.
'\''));
197 'CRM_ENTITY_ID' =>
'ID',
199 'CRM_ENTITY_TYPE_ID',
201 'CRM_CONTACT_ID' =>
'CONTACT_ID',
214 $query = CrmCompanyTable::query();
216 if ($query->getEntity()->hasField(
'CATEGORY_ID'))
218 $query->where(
'CATEGORY_ID', 0);
221 $query->registerRuntimeField(
new Entity\
ExpressionField(
'CRM_ENTITY_TYPE_ID', \CCrmOwnerType::Company));
222 $query->registerRuntimeField(
new Entity\
ExpressionField(
'CRM_ENTITY_TYPE',
'\''.\CCrmOwnerType::CompanyName.
'\''));
229 'CRM_ENTITY_ID' =>
'ID',
231 'CRM_ENTITY_TYPE_ID',
233 'CRM_CONTACT_ID' =>
'CONTACT_ID',
234 'CRM_COMPANY_ID' =>
'COMPANY_ID',
250 $docTypes[] = $docType;
254 foreach (array_keys(self::getCrmDocumentTypes()) as $entityTypeName)
257 if (count($filter) === 0)
262 $docTypes[] = $entityTypeName;
266 foreach ($docTypes as $docType)
268 $refClassName =
"\\Bitrix\\Crm\\" . ucfirst(mb_strtolower($docType)) .
"Table";
269 if (!class_exists($refClassName))
274 if ($query->getEntity()->getName() ===
'Contact')
276 $ref = array(
'=this.ID' =>
'ref.CONTACT_ID');
278 elseif ($query->getEntity()->getName() ===
'Company')
280 $ref = array(
'=this.ID' =>
'ref.COMPANY_ID');
287 $runtimeFieldName =
"SGT_$docType";
289 $joinType = $filter[$docType][
'JOIN_TYPE']??
'INNER';
290 unset($filter[$docType][
'JOIN_TYPE']);
292 $query->registerRuntimeField(
null,
new Entity\ReferenceField(
296 array(
'join_type' => $joinType)
299 foreach ($filter as $key => $value)
301 $pattern =
"/^[\W]{0,2}$docType\./";
302 if (preg_match($pattern, $key))
304 $key = str_replace(
"$docType.",
"$runtimeFieldName.", $key);
307 $query->addFilter($key, $value);
311 foreach ($runtime as $item)
315 str_replace(
"$docType.",
"$runtimeFieldName.", $item[
'expression']),
317 function ($from) use ($docType, $runtimeFieldName)
319 return str_replace(
"$docType.",
"$runtimeFieldName.", $from);
324 $query->registerRuntimeField($item);
328 $entityTypeName = mb_strtoupper($query->getEntity()->getName());
330 foreach ($runtime as $item)
336 function ($from) use ($entityTypeName)
338 return str_replace(
"$entityTypeName.",
"", $from);
343 $query->registerRuntimeField($item);
346 $filterFields = $query->getFilter();
347 if (array_key_exists(
'NO_PURCHASES', $filterFields))
349 $noPurchasesFilter = $filterFields[
'NO_PURCHASES'];
350 $productSource = $filterFields[
'PRODUCT_SOURCE'];
352 unset($filterFields[
'NO_PURCHASES']);
353 $query->setFilter($filterFields);
357 if (array_key_exists(
'DEAL', $filterFields))
361 ->where($filterFields[
'DEAL'])
363 unset($filterFields[
'DEAL']);
364 $query->setFilter($filterFields);
383 $dealQuery = \Bitrix\Crm\DealTable::query();
385 if (is_array($productSource))
388 if (in_array(self::PRODUCT_SOURCE_DEALS_PROCESS, $productSource))
390 $semantics[] = \Bitrix\Crm\PhaseSemantics::PROCESS;
392 if (in_array(self::PRODUCT_SOURCE_DEALS_SUCCESS, $productSource))
394 $semantics[] = \Bitrix\Crm\PhaseSemantics::SUCCESS;
396 if (in_array(self::PRODUCT_SOURCE_DEALS_FAILURE, $productSource))
398 $semantics[] = \Bitrix\Crm\PhaseSemantics::FAILURE;
401 if ($semantics && count($semantics) < 3)
403 $dealQuery->whereIn(
'STAGE_SEMANTIC_ID', $semantics);
408 foreach ($filterValue as $filterCode => $date)
410 $dealsFilter[str_replace(
'%PURCHASE_DATE%',
'DATE_CREATE', $filterCode)] =
413 $dealQuery->setFilter($dealsFilter);
418 $orderQuery = \Bitrix\Crm\Binding\OrderContactCompanyTable::query();
419 $orderQuery->addSelect(
'ENTITY_ID',
'EID');
421 if (is_array($productSource))
423 if (in_array(self::PRODUCT_SOURCE_ORDERS_PAID, $productSource) &&
424 !in_array(self::PRODUCT_SOURCE_ORDERS_UNPAID, $productSource))
426 $orderQuery->where(
'ORDER.PAYED',
true);
428 if (!in_array(self::PRODUCT_SOURCE_ORDERS_PAID, $productSource) &&
429 in_array(self::PRODUCT_SOURCE_ORDERS_UNPAID, $productSource))
431 $orderQuery->where(
'ORDER.PAYED',
false);
434 $orderQuery->whereNotNull(
'ENTITY_ID');
437 foreach ($filterValue as $filterCode => $date)
439 $ordersFilter[str_replace(
'%PURCHASE_DATE%',
'ORDER.DATE_INSERT', $filterCode)] =
442 $orderQuery->setFilter($ordersFilter);
445 if ($query->getEntity()->getName() ===
'Contact')
447 $dealQuery->addSelect(
'CONTACT_ID',
'EID');
448 $dealQuery->whereNotNull(
'CONTACT_ID');
451 $orderQuery->where(
'ENTITY_TYPE_ID', \CCrmOwnerType::Contact);
454 elseif ($query->getEntity()->getName() ===
'Company')
456 $dealQuery->addSelect(
'COMPANY_ID',
'EID');
457 $dealQuery->whereNotNull(
'COMPANY_ID');
460 $orderQuery->where(
'ENTITY_TYPE_ID', \CCrmOwnerType::Company);
464 $dealsAreRequired = empty($productSource) ||
465 array_intersect($productSource, [self::PRODUCT_SOURCE_DEALS_PROCESS, self::PRODUCT_SOURCE_DEALS_SUCCESS, self::PRODUCT_SOURCE_DEALS_FAILURE]);
466 $ordersAreRequired = empty($productSource) ||
467 array_intersect($productSource, [self::PRODUCT_SOURCE_ORDERS_PAID, self::PRODUCT_SOURCE_ORDERS_UNPAID]);
470 if ($orderQuery && $dealsAreRequired && $ordersAreRequired)
472 $idSubQuery =
new SqlExpression($dealQuery->getQuery() .
' UNION ALL ' . $orderQuery->getQuery());
474 elseif ($orderQuery && $ordersAreRequired)
476 $idSubQuery = $orderQuery;
478 elseif ($dealsAreRequired)
480 $idSubQuery = $dealQuery;
484 $query->whereNotIn(
'ID', $idSubQuery);
492 $filterFields = $query->getFilter();
493 $productSource = $filterFields[
'PRODUCT_SOURCE'] ??
'';
494 unset($filterFields[
'PRODUCT_SOURCE']);
495 $query->setFilter($filterFields);
497 $productFilterKey =
'=PRODUCT_ID';
498 if (array_key_exists($productFilterKey, $filterFields))
500 $productIds = $filterFields[$productFilterKey];
502 unset($filterFields[$productFilterKey]);
503 $query->setFilter($filterFields);
505 $productIds = array_merge($productIds, $this->
getProductSkuIds($productIds));
506 if (empty($productIds))
520 '=this.ID' =>
'ref.ENTITY_ID',
524 $entityName = $query->getEntity()->getName();
525 if ($entityName ===
'Contact')
527 $orderRef[
'ref.ENTITY_TYPE_ID'] =
new SqlExpression(
'?i', \CCrmOwnerType::Contact);
528 $dealRef[
'=this.ID'] =
'ref.CONTACT_ID';
531 elseif ($entityName ===
'Company')
533 $orderRef[
'ref.ENTITY_TYPE_ID'] =
new SqlExpression(
'?i', \CCrmOwnerType::Company);
534 $dealRef[
'=this.ID'] =
'ref.COMPANY_ID';
542 $query->whereIn(
'SGT_DEAL.PRODUCT_ROW.PRODUCT_ID', $productIds);
545 if (is_array($productSource))
547 if (in_array(self::PRODUCT_SOURCE_DEALS_PROCESS, $productSource))
549 $semantics[] = \Bitrix\Crm\PhaseSemantics::PROCESS;
551 if (in_array(self::PRODUCT_SOURCE_DEALS_SUCCESS, $productSource))
553 $semantics[] = \Bitrix\Crm\PhaseSemantics::SUCCESS;
555 if (in_array(self::PRODUCT_SOURCE_DEALS_FAILURE, $productSource))
557 $semantics[] = \Bitrix\Crm\PhaseSemantics::FAILURE;
561 switch (count($semantics))
564 $dealRef[
'ref.STAGE_SEMANTIC_ID'] =
new SqlExpression(
'?', $semantics[0]);
567 $dealRef[
'@ref.STAGE_SEMANTIC_ID'] =
new SqlExpression(
'?, ?', $semantics[0], $semantics[1]);
571 $query->registerRuntimeField(
new Entity\ReferenceField(
573 '\Bitrix\Crm\DealTable',
575 array(
'join_type' =>
'LEFT')
578 $query->addSelect(
"SGT_DEAL.ID",
"SGT_DEAL_ID");
579 $extraQuery->setFilter($query->getFilter());
581 $extraQuery->registerRuntimeField(
new Entity\ReferenceField(
583 '\Bitrix\Crm\Binding\OrderContactCompanyTable',
585 array(
'join_type' =>
'LEFT')
587 $extraQuery->addSelect(
"PROD_CRM_ORDER.ID",
"PROD_CRM_ORDER_ID");
589 $extraQuery->registerRuntimeField(
new Entity\ReferenceField(
590 'PROD_CRM_ORDER_PRODUCT',
591 '\Bitrix\Sale\Internals\BasketTable',
593 '=this.PROD_CRM_ORDER.ORDER_ID' =>
'ref.ORDER_ID'
595 array(
'join_type' =>
'LEFT')
598 $extraQuery->whereIn(
'PROD_CRM_ORDER_PRODUCT.PRODUCT_ID', $productIds);
600 if (is_array($productSource))
602 if (in_array(self::PRODUCT_SOURCE_ORDERS_PAID, $productSource) &&
603 !in_array(self::PRODUCT_SOURCE_ORDERS_UNPAID, $productSource))
605 $extraQuery->where(
'PROD_CRM_ORDER.ORDER.PAYED',
true);
607 if (!in_array(self::PRODUCT_SOURCE_ORDERS_PAID, $productSource) &&
608 in_array(self::PRODUCT_SOURCE_ORDERS_UNPAID, $productSource))
610 $extraQuery->where(
'PROD_CRM_ORDER.ORDER.PAYED',
false);
615 $dealsAreRequired = empty($productSource) ||
616 array_intersect($productSource, [self::PRODUCT_SOURCE_DEALS_PROCESS, self::PRODUCT_SOURCE_DEALS_SUCCESS, self::PRODUCT_SOURCE_DEALS_FAILURE]);
617 $ordersAreRequired = empty($productSource) ||
618 array_intersect($productSource, [self::PRODUCT_SOURCE_ORDERS_PAID, self::PRODUCT_SOURCE_ORDERS_UNPAID]);
621 if (
$dataTypeId == Type::CRM_ORDER_PRODUCT_CONTACT_ID && $ordersAreRequired)
623 if ($entityName ===
'Contact')
625 $result[] = $extraQuery;
628 elseif (
$dataTypeId == Type::CRM_ORDER_PRODUCT_COMPANY_ID && $ordersAreRequired)
630 if ($entityName ===
'Company')
632 $result[] = $extraQuery;
635 elseif (
$dataTypeId == Type::CRM_DEAL_PRODUCT_CONTACT_ID && $dealsAreRequired)
637 if ($entityName ===
'Contact')
642 elseif (
$dataTypeId == Type::CRM_DEAL_PRODUCT_COMPANY_ID && $dealsAreRequired)
644 if ($entityName ===
'Company')
651 if ($dealsAreRequired)
655 if ($ordersAreRequired)
657 $result[] = $extraQuery;
670 if ($this->crmEntityFilter ===
null)
673 self::getUiFilterFields(),
675 array_keys(self::getCrmDocumentTypes())
679 if (isset($this->crmEntityFilter[$entityTypeName]))
681 $filter = $this->crmEntityFilter[$entityTypeName];
688 if ($isReferenced && count($filter) === 0)
693 $commonNames = [
'ASSIGNED_BY_ID',
'EMAIL',
'PHONE',
'NAME'];
696 $commonNames = [
'ASSIGNED_BY_ID'];
698 foreach ($commonNames as $commonName)
706 if (in_array($commonName, [
'EMAIL',
'PHONE',
'NAME']))
708 $commonName =
"%$entityTypeName.$commonName";
712 $commonName =
"=$entityTypeName.$commonName";
714 $filter[$commonName] = $value;
722 foreach ($filter as $key => $value)
724 $pattern =
"/^([\W]{0,2})$entityTypeName\./";
725 if (!preg_match($pattern, $key))
730 unset($filter[$key]);
731 $key = preg_replace($pattern,
'$1', $key);
732 $filter[$key] = $value;
824 'sender_segment_filter' =>
'%EMAIL',
825 'sender_internal' => true
830 'sender_segment_filter' =>
'%PHONE',
831 'sender_internal' => true
836 'sender_segment_filter' =>
'%NAME',
837 'sender_internal' => true
842 'params' => array(
'hidden' => self::YES),
845 'filter_callback' => [
'\Bitrix\Sender\Integration\Crm\Connectors\Helper',
'getIdFilter']
851 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DOC_TYPE'),
853 "items" => self::getCrmDocumentTypes(),
854 "sender_segment_filter" =>
false,
859 "id" =>
"CLIENT_TYPE",
860 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CLIENT_TYPE'),
864 'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CLIENT_TYPE_NOT_SET',
866 '%default%' => \CCrmOwnerType::getDescription(\CCrmOwnerType::Contact) .
", " . \CCrmOwnerType::getDescription(\CCrmOwnerType::Company),
869 \CCrmOwnerType::ContactName => \CCrmOwnerType::getDescription(\CCrmOwnerType::Contact),
870 \CCrmOwnerType::CompanyName => \CCrmOwnerType::getDescription(\CCrmOwnerType::Company),
872 "sender_segment_filter" =>
false,
877 "id" =>
"DEAL_DATE_CREATE",
878 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_DATE_CREATE'),
881 AdditionalDateType::CUSTOM_DATE,
882 AdditionalDateType::PREV_DAY,
883 AdditionalDateType::NEXT_DAY,
884 AdditionalDateType::MORE_THAN_DAYS_AGO,
885 AdditionalDateType::AFTER_DAYS,
887 "allow_years_switcher" =>
true,
893 "id" =>
"DEAL_STAGE_ID",
894 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_STATUS_ID'),
896 'params' => array(
'multiple' => self::YES),
897 "items" => $stageList,
902 "id" =>
"CONTACT_SOURCE_ID",
903 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CONTACT_SOURCE_ID'),
905 'params' => array(
'multiple' => self::YES),
906 "items" => \CCrmStatus::GetStatusList(
'SOURCE'),
911 'id' =>
'CLIENT_COMMUNICATION_TYPE',
912 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_COMMUNICATION_TYPE'),
913 'params' => array(
'multiple' => self::YES),
916 'items' => \CCrmFieldMulti::PrepareListItems(array(
917 \CCrmFieldMulti::PHONE,
918 \CCrmFieldMulti::EMAIL,
921 'filter_callback' => [
'\Bitrix\Sender\Integration\Crm\Connectors\Helper',
'getCommunicationTypeFilter']
925 "id" =>
"CLIENT_NO_PURCHASES_DATE",
926 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_NO_PURCHASES_DATE'),
929 \
Bitrix\Main\UI\Filter\DateType::TOMORROW,
930 \
Bitrix\Main\UI\Filter\DateType::NEXT_DAYS,
931 \
Bitrix\Main\UI\Filter\DateType::NEXT_WEEK,
932 \
Bitrix\Main\UI\Filter\DateType::NEXT_MONTH,
936 'MAIN_UI_FILTER_FIELD_SUBTYPE_NONE' =>
''
938 'filter_callback' => [
'\Bitrix\Sender\Integration\Crm\Connectors\Helper',
'getNoPurchasesFilter']
944 'id' =>
'CLIENT_PRODUCT_ID',
945 "name" =>
Loc::getMessage(
"SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_PRODUCT_ID"),
947 'type' =>
'dest_selector',
950 'multiple' => self::YES,
951 'apiVersion' => self::API_VERSION,
952 'context' =>
'SENDER_FILTER_PRODUCT_ID',
953 'contextCode' =>
'CRM',
954 'useClientDatabase' => self::NO,
955 'enableAll' => self::NO,
956 'enableDepartments' => self::NO,
957 'enableUsers' => self::NO,
958 'enableSonetgroups' => self::NO,
959 'allowEmailInvitation' => self::NO,
960 'allowSearchEmailUsers' => self::NO,
961 'departmentSelectDisable' => self::YES,
962 'addTabCrmProducts' => self::YES,
963 'enableCrm' => self::YES,
964 'enableCrmProducts' => self::YES,
965 'convertJson' => self::YES
970 'id' =>
'CLIENT_PRODUCT_SOURCE',
971 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE'),
975 'multiple' => self::YES,
978 "" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE_ANY'),
979 self::PRODUCT_SOURCE_ORDERS_PAID =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE_ORDERS_PAID'),
980 self::PRODUCT_SOURCE_ORDERS_UNPAID =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE_ORDERS_UNPAID'),
981 self::PRODUCT_SOURCE_DEALS_PROCESS =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE_DEALS_PROCESS'),
982 self::PRODUCT_SOURCE_DEALS_SUCCESS =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE_DEALS_SUCCESS'),
983 self::PRODUCT_SOURCE_DEALS_FAILURE =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_PRODUCT_SOURCE_DEALS_FAILURE'),
985 'filter_callback' => [
'\Bitrix\Sender\Integration\Crm\Connectors\Helper',
'productSourceFilter']
991 'id' =>
'DEAL_PRODUCT_ROW.PRODUCT_ID',
992 "name" =>
Loc::getMessage(
"SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_PRODUCT_ID"),
994 'type' =>
'dest_selector',
997 'multiple' => self::YES,
998 'apiVersion' => self::API_VERSION,
999 'context' =>
'SENDER_FILTER_PRODUCT_ID',
1000 'contextCode' =>
'CRM',
1001 'useClientDatabase' => self::NO,
1002 'enableAll' => self::NO,
1003 'enableDepartments' => self::NO,
1004 'enableUsers' => self::NO,
1005 'enableSonetgroups' => self::NO,
1006 'allowEmailInvitation' => self::NO,
1007 'allowSearchEmailUsers' => self::NO,
1008 'departmentSelectDisable' => self::YES,
1009 'addTabCrmProducts' => self::YES,
1010 'enableCrm' => self::YES,
1011 'enableCrmProducts' => self::YES,
1012 'convertJson' => self::YES
1018 $list[] = PhaseSemantics::getListFilterInfo(
1019 \CCrmOwnerType::Deal,
1021 'id' =>
'DEAL_STAGE_SEMANTIC_ID',
1022 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_STATUS_SEMANTIC_ID'),
1024 'params' => array(
'multiple' => self::YES)
1030 "id" =>
"CONTACT_POST",
1032 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CONTACT_POST'),
1033 'params' => array(
'multiple' => self::YES),
1038 "id" =>
"ASSIGNED_BY_ID",
1039 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_ASSIGNED_BY_ID'),
1040 'type' =>
'dest_selector',
1042 'context' =>
'SENDER_FILTER_ASSIGNED_BY_ID',
1043 'multiple' => self::YES,
1044 'contextCode' =>
'U',
1045 'enableAll' => self::NO,
1046 'enableSonetgroups' => self::NO,
1047 'allowEmailInvitation' => self::NO,
1048 'allowSearchEmailUsers' => self::NO,
1049 'departmentSelectDisable' => self::YES,
1050 'isNumeric' => self::YES,
1053 "sender_segment_filter" =>
false,
1057 foreach ([\CCrmOwnerType::Company, \CCrmOwnerType::Contact, \CCrmOwnerType::Deal] as $entityTypeId)
1059 $entityTypeCaption = \CCrmOwnerType::getDescription($entityTypeId);
1060 $entityTypeName = \CCrmOwnerType::resolveName($entityTypeId);
1061 $fieldId =
"{$entityTypeName}_ASSIGNED_BY_ID";
1064 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_ASSIGNED_BY_ID') .
" ($entityTypeCaption)",
1065 'type' =>
'dest_selector',
1067 'context' =>
'SENDER_FILTER_ASSIGNED_BY_ID',
1068 'multiple' => self::YES,
1069 'contextCode' =>
'U',
1070 'enableAll' => self::NO,
1071 'enableSonetgroups' => self::NO,
1072 'allowEmailInvitation' => self::NO,
1073 'allowSearchEmailUsers' => self::NO,
1074 'departmentSelectDisable' => self::YES,
1075 'isNumeric' => self::YES,
1084 "id" =>
"CONTACT_BIRTHDATE",
1085 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CONTACT_BIRTHDATE'),
1088 AdditionalDateType::CUSTOM_DATE,
1089 AdditionalDateType::PREV_DAY,
1090 AdditionalDateType::NEXT_DAY,
1091 AdditionalDateType::MORE_THAN_DAYS_AGO,
1092 AdditionalDateType::AFTER_DAYS,
1094 "allow_years_switcher" =>
true,
1100 'id' => self::DEAL_CATEGORY_ID,
1101 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_CATEGORY_ID_MSG_1'),
1102 'params' => array(
'multiple' => self::YES),
1106 'valueRequired' =>
true,
1107 'items' => self::getDealCategoryList(),
1108 'filter_callback' => [
'\Bitrix\Sender\Integration\Crm\Connectors\Helper',
'getDealCategoryFilter']
1112 "id" =>
"DEAL_TYPE_ID",
1113 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_TYPE_ID'),
1115 'params' => array(
'multiple' => self::YES),
1116 "items" => \CCrmStatus::GetStatusList(
'DEAL_TYPE'),
1121 "id" =>
"DEAL_OPPORTUNITY",
1122 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_OPPORTUNITY'),
1128 "id" =>
"DEAL_CLOSEDATE",
1129 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_DEAL_CLOSEDATE'),
1132 AdditionalDateType::CUSTOM_DATE,
1133 AdditionalDateType::PREV_DAY,
1134 AdditionalDateType::NEXT_DAY,
1135 AdditionalDateType::MORE_THAN_DAYS_AGO,
1136 AdditionalDateType::AFTER_DAYS,
1138 "allow_years_switcher" =>
true,
1143 'id' =>
'COMPANY_COMPANY_TYPE',
1144 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_COMPANY_TYPE'),
1145 'params' => array(
'multiple' => self::YES),
1148 'items' => \CCrmStatus::GetStatusList(
'COMPANY_TYPE'),
1152 'id' =>
'CONTACT_TYPE_ID',
1153 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CONTACT_TYPE'),
1154 'params' => array(
'multiple' => self::YES),
1157 'items' => \CCrmStatus::GetStatusList(
'CONTACT_TYPE'),
1161 'id' =>
'CONTACT_HONORIFIC',
1162 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_CONTACT_HONORIFIC'),
1163 'params' => array(
'multiple' => self::YES),
1166 'items' => \CCrmStatus::GetStatusList(
'HONORIFIC'),
1170 'id' =>
'COMPANY_INDUSTRY',
1171 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_FIELD_COMPANY_INDUSTRY'),
1172 'params' => array(
'multiple' => self::YES),
1175 'items' => \CCrmStatus::GetStatusList(
'INDUSTRY'),
1179 $entityTypes = array_merge(
1181 \CCrmOwnerType::ContactName,
1182 \CCrmOwnerType::CompanyName,
1184 array_keys(self::getCrmDocumentTypes())
1186 foreach ($entityTypes as $entityTypeName)
1188 $entityTypeId = \CCrmOwnerType::resolveId($entityTypeName);
1189 $entityTypeCaption = \CCrmOwnerType::getDescription($entityTypeId);
1191 foreach ($ufList as $item)
1193 if (isset($item[
'name']))
1195 $item[
'name'] .=
" ($entityTypeCaption)";
1197 elseif (isset($item[
'NAME']))
1199 $item[
'NAME'] .=
" ($entityTypeCaption)";
1202 if (isset($item[
'id']))
1204 $item[
'id'] = $entityTypeName .
"_" . $item[
'id'];
1206 elseif (isset($item[
'ID']))
1208 $item[
'ID'] = $entityTypeName .
"_" . $item[
'ID'];
1226 'crm_client_all' => array(
1227 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_ALL'),
1228 'sender_segment_name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_SEGMENT_ALL'),
1230 self::FIELD_FOR_PRESET_ALL => self::YES,
1233 'crm_client_deal_in_work' => array(
1234 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_DEAL_INW'),
1235 'sender_segment_name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_SEGMENT_DEAL_INW'),
1237 'DEAL_STAGE_SEMANTIC_ID' => array(PhaseSemantics::PROCESS),
1240 'crm_client_deal_won' => array(
1241 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_DEAL_WON'),
1242 'sender_segment_name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_SEGMENT_DEAL_WON'),
1244 'DEAL_STAGE_SEMANTIC_ID' => array(PhaseSemantics::SUCCESS),
1247 'crm_client_deal_loose' => array(
1248 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_DEAL_LOOSE'),
1249 'sender_segment_name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_SEGMENT_DEAL_LOOSE'),
1251 'DEAL_STAGE_SEMANTIC_ID' => array(PhaseSemantics::FAILURE),
1254 'crm_client_birthday' => array(
1255 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_BIRTH'),
1256 'sender_segment_name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_SEGMENT_BIRTH'),
1257 'sender_segment_business_case' =>
true,
1259 'CONTACT_BIRTHDATE_datesel' =>
'NEXT_DAY',
1260 'CONTACT_BIRTHDATE_days' =>
'5',
1261 'CONTACT_BIRTHDATE_allow_year' =>
'0',
1262 'CLIENT_TYPE' => \CCrmOwnerType::ContactName
1265 'crm_client_aft_deal_clo' => array(
1266 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_AFTER_CLOSE_DEAL'),
1267 'sender_segment_name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_SEGMENT_AFTER_CLOSE_DEAL'),
1268 'sender_segment_business_case' =>
true,
1270 'DEAL_CLOSEDATE_datesel' =>
'PREV_DAY',
1271 'DEAL_CLOSEDATE_days' =>
"30",
1272 'DEAL_CLOSEDATE_allow_year' =>
'1',
1279 $code = $holiday->getCode();
1280 $name = $holiday->getName(
1281 Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_CLIENT_PRESET_HOLIDAY'),
1285 $list[
"crm_client_$code"] = [
1287 'sender_segment_name' => $name,
1288 'sender_segment_business_case' =>
true,
1290 'DEAL_DATE_CREATE_datesel' =>
'RANGE',
1291 'DEAL_DATE_CREATE_from' => $holiday->getDateFrom()->toString(),
1292 'DEAL_DATE_CREATE_to' => $holiday->getDateTo()->toString(),
1293 'DEAL_DATE_CREATE_allow_year' =>
'0',