• Модуль: voximplant
  • Путь к файлу: ~/bitrix/modules/voximplant/classes/general/vi_crm_helper.php
  • Класс: CVoxImplantCrmHelper
  • Вызов: CVoxImplantCrmHelper::GetDataForPopup
static function GetDataForPopup($callId, $phone, $userId = 0)
{
	if ($phone == '' || !CModule::IncludeModule('crm'))
	{
		return false;
	}

	if ($userId > 0)
	{
		$findParams = array('USER_ID'=> $userId);
	}
	else
	{
		$findParams = array('ENABLE_EXTENDED_MODE'=> false);
	}

	$call = VICall::load($callId);
	$arResult = Array('FOUND' => 'N');
	$found = false;
	$entity = '';
	$entityData = Array();
	$entities = Array();

	if($call->getPrimaryEntityType() && $call->getPrimaryEntityId() > 0)
	{
		$entityTypeId = CCrmOwnerType::ResolveID($call->getPrimaryEntityType());
		$entityId = $call->getPrimaryEntityId();

		$entityFields = CCrmSipHelper::getEntityFields($entityTypeId, $entityId, $findParams);

		if(is_array($entityFields))
		{
			$found = true;
			$entity = $call->getPrimaryEntityType();
			$entityData = $entityFields;
			$arResult = self::convertEntityFields($call->getPrimaryEntityType(), $entityData);
			$entities = array($entity);
			$crm = array(
				$entity => array(
					0 => $entityData
				)
			);
		}
	}

	foreach ($entities as $entity)
	{
		if (isset($crm[$entity][0]['ACTIVITIES']))
		{
			foreach ($crm[$entity][0]['ACTIVITIES'] as $activity)
			{
				$overdue = 'N';
				if ($activity['DEADLINE'] <> '' && MakeTimeStamp($activity['DEADLINE']) < time())
				{
					$overdue = 'Y';
				}

				$arResult['ACTIVITIES'][$activity['ID']] = Array(
					'TITLE' => $activity['SUBJECT'],
					'DATE' => $activity['DEADLINE'] <> ''? $activity['DEADLINE']: $activity['END_TIME'],
					'OVERDUE' => $overdue,
					'URL' => $activity['SHOW_URL'],
				);
			}
			if (!empty($arResult['ACTIVITIES']))
			{
				$arResult['ACTIVITIES'] = array_values($arResult['ACTIVITIES']);
			}
		}

		if (isset($crm[$entity][0]['DEALS']))
		{
			foreach ($crm[$entity][0]['DEALS'] as $deal)
			{
				$opportunity = CCrmCurrency::MoneyToString($deal['OPPORTUNITY'], $deal['CURRENCY_ID']);
				if(mb_strpos('&', $opportunity))
				{
					$opportunity = CCrmCurrency::MoneyToString($deal['OPPORTUNITY'], $deal['CURRENCY_ID'], '#').' '.$deal['CURRENCY_ID'];
				}
				$opportunity = str_replace('.00', '', $opportunity);

				$arResult['DEALS'][$deal['ID']] = Array(
					'ID' => $deal['ID'],
					'TITLE' => $deal['TITLE'],
					'STAGE' => $deal['STAGE_NAME'],
					'STAGE_COLOR' => $deal['STAGE_COLOR'] ? $deal['STAGE_COLOR'] : "#5fa0ce",
					'OPPORTUNITY' => $opportunity,
					'OPPORTUNITY_VALUE' => $deal['OPPORTUNITY'],
					'CURRENCY_ID' => $deal['CURRENCY_ID'],
					'URL' => $deal['SHOW_URL'],
					'REPEATED_TEXT' => $deal['REPEATED_TEXT'],
					'CREATED_TIME' => $deal['CREATED_TIME'],
				);
			}
			if (!empty($arResult['DEALS']))
			{
				$arResult['DEALS'] = array_values($arResult['DEALS']);
			}
		}
	}

	if(!$found)
	{
		$arResult = array('FOUND' => 'N');
		$userPermissions = CCrmPerms::GetUserPermissions($userId);
		if (CCrmLead::CheckCreatePermission($userPermissions))
		{
			$arResult['CAN_CREATE_LEAD'] = self::isLeadEnabled();
			$arResult['LEAD_URL'] = CCrmOwnerType::GetEditUrl(CCrmOwnerType::Lead, 0);
			if($arResult['LEAD_URL'] !== '')
			{
				$arResult['LEAD_URL'] = CCrmUrlUtil::AddUrlParams($arResult['LEAD_URL'], array("phone" => (string)$phone, 'origin_id' => 'VI_'.$callId));
				$arResult['ORIGIN_ID'] = 'VI_'.$callId;
			}
		}
		if (CCrmContact::CheckCreatePermission($userPermissions))
		{
			$arResult['CONTACT_URL'] = CCrmOwnerType::GetEditUrl(CCrmOwnerType::Contact, 0);
			if($arResult['CONTACT_URL'] !== '')
			{
				$arResult['CONTACT_URL'] = CCrmUrlUtil::AddUrlParams($arResult['CONTACT_URL'], array("phone" => (string)$phone, 'origin_id' => 'VI_'.$callId));
				$arResult['ORIGIN_ID'] = 'VI_'.$callId;
			}
		}
	}
	return $arResult;
}