60 self::getUiFilterFields(),
65 $sqlHelper = \Bitrix\Main\Application::getConnection()->getSqlHelper();
68 $sqlHelper->quote(
'NAME'),
70 WHEN %2$s=\'Y\' AND %3$s>0 THEN %4$s
71 WHEN %2$s=\'Y\' AND %5$s>0 THEN %6$s
75 'NAME',
'IS_RETURN_CUSTOMER',
76 'CONTACT_ID',
'CONTACT.NAME',
77 'COMPANY_ID',
'COMPANY.TITLE'
82 $query->setFilter($filter);
83 $query->setSelect(array_merge($selectList, [
85 'CRM_ENTITY_ID' =>
'ID',
88 'CRM_CONTACT_ID' =>
'CONTACT_ID',
89 'CRM_COMPANY_ID' =>
'COMPANY_ID',
92 $query->registerRuntimeField(
new Entity\
ExpressionField(
'CRM_ENTITY_TYPE',
'\''.\CCrmOwnerType::LeadName.
'\''));
95 \CCrmOwnerType::LeadName,
99 \CCrmOwnerType::LeadName,
102 $query->registerRuntimeField(
new Entity\
ExpressionField(
'CRM_ENTITY_TYPE_ID', \CCrmOwnerType::Lead));
103 $query->registerRuntimeField(
null,
new Entity\ReferenceField(
105 "\\Bitrix\\Crm\\ContactTable",
106 [
'=this.CONTACT_ID' =>
'ref.ID'],
107 [
'join_type' =>
'LEFT']
109 $query->registerRuntimeField(
null,
new Entity\ReferenceField(
111 "\\Bitrix\\Crm\\CompanyTable",
112 [
'=this.COMPANY_ID' =>
'ref.ID'],
113 [
'join_type' =>
'LEFT']
115 foreach ($runtime as $item)
122 $query->registerRuntimeField($item);
194 'sender_segment_filter' =>
'%EMAIL',
195 'sender_internal' => true
200 'sender_segment_filter' =>
'%PHONE',
201 'sender_internal' => true
206 'sender_segment_filter' =>
'%NAME',
207 'sender_internal' => true
212 "id" =>
"DATE_CREATE",
213 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_LEAD_FIELD_DATE_CREATE'),
216 AdditionalDateType::CUSTOM_DATE,
217 AdditionalDateType::PREV_DAY,
218 AdditionalDateType::NEXT_DAY,
219 AdditionalDateType::MORE_THAN_DAYS_AGO,
220 AdditionalDateType::AFTER_DAYS,
222 "allow_years_switcher" =>
true,
228 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_LEAD_FIELD_STATUS_ID'),
230 "items" => \CCrmStatus::GetStatusList(
'STATUS'),
232 'params' => array(
'multiple' =>
'Y'),
237 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_LEAD_FIELD_SOURCE_ID'),
239 "items" => \CCrmStatus::GetStatusList(
'SOURCE'),
241 'params' => array(
'multiple' =>
'Y'),
245 'id' =>
'COMMUNICATION_TYPE',
246 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_LEAD_FIELD_COMMUNICATION_TYPE'),
247 'params' => array(
'multiple' =>
'Y'),
250 'items' => \CCrmFieldMulti::PrepareListItems(array(
251 \CCrmFieldMulti::PHONE,
252 \CCrmFieldMulti::EMAIL,
255 'filter_callback' => [
'\Bitrix\Sender\Integration\Crm\Connectors\Helper',
'getCommunicationTypeFilter']
258 $list[] = PhaseSemantics::getListFilterInfo(
259 \CCrmOwnerType::Lead,
261 'id' =>
'STATUS_SEMANTIC_ID',
262 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_LEAD_FIELD_STATUS_SEMANTIC_ID'),
264 'params' => array(
'multiple' =>
'Y'),
270 'id' =>
'PRODUCT_ROW.PRODUCT_ID',
271 "name" =>
Loc::getMessage(
"SENDER_INTEGRATION_CRM_CONNECTOR_LEAD_FIELD_PRODUCT_ID"),
273 'type' =>
'dest_selector',
278 'context' =>
'CRM_LEAD_FILTER_PRODUCT_ID',
279 'contextCode' =>
'CRM',
280 'useClientDatabase' =>
'N',
282 'enableDepartments' =>
'N',
283 'enableUsers' =>
'N',
284 'enableSonetgroups' =>
'N',
285 'allowEmailInvitation' =>
'N',
286 'allowSearchEmailUsers' =>
'N',
287 'departmentSelectDisable' =>
'Y',
288 'addTabCrmProducts' =>
'Y',
290 'enableCrmProducts' =>
'Y',
296 "id" =>
"STATUS_CONVERTED",
297 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_LEAD_FIELD_STATUS_CONVERTED'),
298 'type' =>
'checkbox',
299 'sender_segment_filter' => array(
300 'N' => array(
'=STATUS_SEMANTIC_ID', PhaseSemantics::PROCESS),
301 'Y' => array(
'!=STATUS_SEMANTIC_ID', PhaseSemantics::PROCESS),
307 "id" =>
"ASSIGNED_BY_ID",
308 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_LEAD_FIELD_ASSIGNED_BY_ID'),
309 'type' =>
'dest_selector',
311 'context' =>
'SENDER_LEAD_FILTER_ASSIGNED_BY_ID',
313 'contextCode' =>
'U',
315 'enableSonetgroups' =>
'N',
316 'allowEmailInvitation' =>
'N',
317 'allowSearchEmailUsers' =>
'N',
318 'departmentSelectDisable' =>
'Y',
328 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_LEAD_FIELD_POST'),
329 'params' => array(
'multiple' =>
'Y'),
335 "name" =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_LEAD_FIELD_BIRTHDATE'),
338 AdditionalDateType::CUSTOM_DATE,
339 AdditionalDateType::PREV_DAY,
340 AdditionalDateType::NEXT_DAY,
341 AdditionalDateType::MORE_THAN_DAYS_AGO,
342 AdditionalDateType::AFTER_DAYS,
344 "allow_years_switcher" =>
true,
350 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_CRM_CONNECTOR_LEAD_FIELD_HONORIFIC'),
351 'params' => array(
'multiple' =>
'Y'),
354 'items' => \CCrmStatus::GetStatusList(
'HONORIFIC'),
510 $query = LeadTable::query()
511 ->setSelect([
'NAME',
'LAST_NAME',
'POST',
'HONORIFIC',
'BIRTHDATE',
'HAS_EMAIL',
'HAS_IMOL',
'HAS_PHONE'])
512 ->where(
'ID', $leadId);
515 if ($lead = $query->fetch())
517 $contactsFields = [];
520 ($lead[
'HAS_EMAIL'] ===
'Y')
521 || ($lead[
'HAS_IMOL'] ===
'Y')
522 || ($lead[
'HAS_PHONE'] ===
'Y')
525 $leadMultiFields = Container::getInstance()
526 ->getMultifieldStorage()
527 ->get(
new \
Bitrix\Crm\ItemIdentifier(\CCrmOwnerType::Lead, $leadId));
528 $contactsFields = $leadMultiFields->toArray();
532 'NAME' => $lead[
'NAME'],
533 'LAST_NAME' => $lead[
'LAST_NAME'],
534 'POST' => $lead[
'POST'],
535 'HONORIFIC' => $lead[
'HONORIFIC'],
536 'BIRTHDATE' => $lead[
'BIRTHDATE'],
537 'FM' => $contactsFields,