private static function ResolveEntityInfo($typeID, $ID) { $typeID = intval($typeID); $ID = intval($ID); if (!(CCrmOwnerType::IsDefined($typeID) && $ID > 0)) { return array('TYPE_ID' => $typeID, 'TYPE_NAME' => CCrmOwnerType::ResolveName($typeID), 'ID' => $ID); } $fields = null; if ($typeID === CCrmOwnerType::Lead) { $fields = CCrmLead::GetByID($ID, false); } elseif ($typeID === CCrmOwnerType::Contact) { $fields = CCrmContact::GetByID($ID, false); } elseif ($typeID === CCrmOwnerType::Company) { $fields = CCrmCompany::GetByID($ID, false); } elseif ($typeID === CCrmOwnerType::Deal) { $fields = CCrmDeal::GetByID($ID, false); } return array('TYPE_ID' => $typeID, 'TYPE_NAME' => CCrmOwnerType::ResolveName($typeID), 'ID' => $ID, 'FIELDS' => $fields); }
if (isset($arCompany['LEAD_ID']) && intval($arCompany['LEAD_ID']) > 0) { $arFields['~LEAD_ID'] = $arFields['LEAD_ID'] = intval($arCompany['LEAD_ID']); } } unset($dbCompany, $arCompany); } // create from lead if ($leadId > 0) { $dbDeal = CCrmDeal::GetListEx(array('ID' => 'DESC'), array('LEAD_ID' => $leadId), false, array('nTopCount' => 1), array('ID')); if ($arDeal = $dbDeal->Fetch()) { if (isset($arDeal['ID']) && intval($arDeal['ID']) > 0) { $arFields['~DEAL_ID'] = $arFields['DEAL_ID'] = intval($arDeal['ID']); } } unset($dbDeal, $arDeal); if (($arLead = CCrmLead::GetByID($leadId)) && is_array($arLead)) { // get contact and/or company from lead if ($companyId <= 0 || $contactId <= 0) { if (isset($arLead['CONTACT_ID']) && intval($arLead['CONTACT_ID']) > 0) { $arFields['~CONTACT_ID'] = $arFields['CONTACT_ID'] = intval($arLead['CONTACT_ID']); } if (isset($arLead['COMPANY_ID']) && intval($arLead['COMPANY_ID']) > 0) { $arFields['~COMPANY_ID'] = $arFields['COMPANY_ID'] = intval($arLead['COMPANY_ID']); } } if (isset($arLead['TITLE']) && !isset($arFields['~TITLE'])) { $arFields['~TITLE'] = $arLead['TITLE']; $arFields['TITLE'] = htmlspecialcharsbx($arLead['TITLE']); } if (isset($arLead['ASSIGNED_BY_ID']) && intval($arLead['ASSIGNED_BY_ID']) > 0) { $arFields['~ASSIGNED_BY_ID'] = $arFields['ASSIGNED_BY_ID'] = intval($arLead['ASSIGNED_BY_ID']);
$ID = isset($_REQUEST['ID']) ? intval($_REQUEST['ID']) : 0; $typeName = isset($_REQUEST['TYPE']) ? $_REQUEST['TYPE'] : ''; $statusID = isset($_REQUEST['VALUE']) ? $_REQUEST['VALUE'] : ''; $targetTypeName = CCrmOwnerType::ResolveName(CCrmOwnerType::Lead); if ($statusID === '' || $ID <= 0 || $typeName !== $targetTypeName) { $APPLICATION->RestartBuffer(); echo CUtil::PhpToJSObject(array('ERROR' => 'Invalid data!')); die; } $entityAttrs = $userPerms->GetEntityAttr($targetTypeName, array($ID)); if (!$userPerms->CheckEnityAccess($targetTypeName, 'WRITE', $entityAttrs[$ID])) { $APPLICATION->RestartBuffer(); echo CUtil::PhpToJSObject(array('ERROR' => 'Access denied!')); die; } $arFields = CCrmLead::GetByID($ID, false); if (!is_array($arFields)) { $APPLICATION->RestartBuffer(); echo CUtil::PhpToJSObject(array('ERROR' => 'Not found!')); die; } if (isset($arFields['CREATED_BY_ID'])) { unset($arFields['CREATED_BY_ID']); } if (isset($arFields['DATE_CREATE'])) { unset($arFields['DATE_CREATE']); } if (isset($arFields['MODIFY_BY_ID'])) { unset($arFields['MODIFY_BY_ID']); } if (isset($arFields['DATE_MODIFY'])) {
public static function PrepareCommunicationInfo(&$arComm, $arFields = null) { if (!isset($arComm['ENTITY_SETTINGS'])) { if (!self::PrepareCommunicationSettings($arComm, $arFields)) { $arComm['TITLE'] = ''; $arComm['DESCRIPTION'] = ''; return false; } } $title = ''; $description = ''; $fullNameFormat = \Bitrix\Crm\Format\PersonNameFormatter::getFormat(); $entityTypeID = isset($arComm['ENTITY_TYPE_ID']) ? intval($arComm['ENTITY_TYPE_ID']) : CCrmOwnerType::Undefined; if ($entityTypeID === CCrmOwnerType::Lead) { $name = ''; $secondName = ''; $lastName = ''; $leadTitle = ''; if (is_array($arComm['ENTITY_SETTINGS'])) { $settings = $arComm['ENTITY_SETTINGS']; $name = isset($settings['NAME']) ? $settings['NAME'] : ''; $secondName = isset($settings['SECOND_NAME']) ? $settings['SECOND_NAME'] : ''; $lastName = isset($settings['LAST_NAME']) ? $settings['LAST_NAME'] : ''; $leadTitle = isset($settings['LEAD_TITLE']) ? $settings['LEAD_TITLE'] : ''; } else { $arEntity = CCrmLead::GetByID($arComm['ENTITY_ID']); if ($arEntity) { $name = isset($arEntity['NAME']) ? $arEntity['NAME'] : ''; $secondName = isset($arEntity['SECOND_NAME']) ? $arEntity['SECOND_NAME'] : ''; $lastName = isset($arEntity['LAST_NAME']) ? $arEntity['LAST_NAME'] : ''; $leadTitle = isset($arEntity['TITLE']) ? $arEntity['TITLE'] : ''; } } if ($name === '' && $secondName === '' && $lastName === '') { $title = $leadTitle; //$description = ''; } else { $title = CUser::FormatName($fullNameFormat, array('LOGIN' => '', 'NAME' => $name, 'SECOND_NAME' => $secondName, 'LAST_NAME' => $lastName), false, false); $description = $leadTitle; } } elseif ($entityTypeID === CCrmOwnerType::Contact) { // Empty TYPE is person to person communiation, empty ENTITY_ID is unbound communication - no method to build title if (!($arComm['TYPE'] === '' && intval($arComm['ENTITY_ID']) === 0)) { $name = ''; $secondName = ''; $lastName = ''; $companyTitle = ''; if (is_array($arComm['ENTITY_SETTINGS'])) { $settings = $arComm['ENTITY_SETTINGS']; $name = isset($settings['NAME']) ? $settings['NAME'] : ''; $secondName = isset($settings['SECOND_NAME']) ? $settings['SECOND_NAME'] : ''; $lastName = isset($settings['LAST_NAME']) ? $settings['LAST_NAME'] : ''; $companyTitle = isset($settings['COMPANY_TITLE']) ? $settings['COMPANY_TITLE'] : ''; } else { $arEntity = CCrmContact::GetByID($arComm['ENTITY_ID']); if ($arEntity) { $name = isset($arEntity['NAME']) ? $arEntity['NAME'] : ''; $secondName = isset($arEntity['SECOND_NAME']) ? $arEntity['SECOND_NAME'] : ''; $lastName = isset($arEntity['LAST_NAME']) ? $arEntity['LAST_NAME'] : ''; $companyTitle = isset($arEntity['COMPANY_TITLE']) ? $arEntity['COMPANY_TITLE'] : ''; } } $title = CUser::FormatName($fullNameFormat, array('LOGIN' => '', 'NAME' => $name, 'SECOND_NAME' => $secondName, 'LAST_NAME' => $lastName), false, false); $description = $companyTitle; } } elseif ($entityTypeID === CCrmOwnerType::Company) { if (is_array($arComm['ENTITY_SETTINGS'])) { $settings = $arComm['ENTITY_SETTINGS']; $title = isset($settings['COMPANY_TITLE']) ? $settings['COMPANY_TITLE'] : ''; } else { $arEntity = CCrmCompany::GetByID($arComm['ENTITY_ID']); if ($arEntity) { $title = isset($arEntity['TITLE']) ? $arEntity['TITLE'] : ''; } } } $arComm['TITLE'] = $title; $arComm['DESCRIPTION'] = $description; return true; }
function GetCrmEntityCommunications($entityType, $entityID, $communicationType) { $fullNameFormat = \Bitrix\Crm\Format\PersonNameFormatter::getFormat(); if ($entityType === 'LEAD') { $data = array('ownerEntityType' => 'LEAD', 'ownerEntityId' => $entityID, 'entityType' => 'LEAD', 'entityId' => $entityID, 'entityTitle' => "{$entityType}_{$entityID}", 'entityDescription' => '', 'tabId' => 'main', 'communications' => array()); $entity = CCrmLead::GetByID($entityID); if (!$entity) { return array('ERROR' => 'Invalid data'); } // Prepare title $name = isset($entity['NAME']) ? $entity['NAME'] : ''; $secondName = isset($entity['SECOND_NAME']) ? $entity['SECOND_NAME'] : ''; $lastName = isset($entity['LAST_NAME']) ? $entity['LAST_NAME'] : ''; if ($name !== '' || $secondName !== '' || $lastName !== '') { $data['entityTitle'] = CUser::FormatName($fullNameFormat, array('LOGIN' => '', 'NAME' => $name, 'SECOND_NAME' => $secondName, 'LAST_NAME' => $lastName), false, false); $data['entityDescription'] = isset($entity['TITLE']) ? $entity['TITLE'] : ''; } else { $data['entityTitle'] = isset($entity['TITLE']) ? $entity['TITLE'] : ''; $data['entityDescription'] = ''; } // Try to load entity communications if (!CCrmActivity::CheckReadPermission(CCrmOwnerType::ResolveID($entityType), $entityID)) { return array('ERROR' => GetMessage('CRM_PERMISSION_DENIED')); } if ($communicationType !== '') { $dbResFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => $entityType, 'ELEMENT_ID' => $entityID, 'TYPE_ID' => $communicationType)); while ($arField = $dbResFields->Fetch()) { if (empty($arField['VALUE'])) { continue; } $comm = array('type' => $communicationType, 'value' => $arField['VALUE']); $data['communications'][] = $comm; } } return array('DATA' => array('TABS' => array(array('id' => 'lead', 'title' => GetMessage('CRM_COMMUNICATION_TAB_LEAD'), 'active' => true, 'items' => array($data))))); } elseif ($entityType === 'DEAL') { $entity = CCrmDeal::GetByID($entityID); if (!$entity) { return array('ERROR' => 'Invalid data'); } $dealData = array(); // Prepare company data $entityCompanyData = null; $entityCompanyID = isset($entity['COMPANY_ID']) ? intval($entity['COMPANY_ID']) : 0; $entityCompany = $entityCompanyID > 0 ? CCrmCompany::GetByID($entityCompanyID) : null; if (is_array($entityCompany)) { $entityCompanyData = array('ownerEntityType' => 'DEAL', 'ownerEntityId' => $entityID, 'entityType' => 'COMPANY', 'entityId' => $entityCompanyID, 'entityTitle' => isset($entityCompany['TITLE']) ? $entityCompany['TITLE'] : '', 'entityDescription' => '', 'communications' => array()); if ($communicationType !== '') { $entityCompanyComms = CCrmActivity::PrepareCommunications('COMPANY', $entityCompanyID, $communicationType); foreach ($entityCompanyComms as &$entityCompanyComm) { $comm = array('type' => $entityCompanyComm['TYPE'], 'value' => $entityCompanyComm['VALUE']); $entityCompanyData['communications'][] = $comm; } unset($entityCompanyComm); } } // Try to get contact of deal $entityContactID = isset($entity['CONTACT_ID']) ? intval($entity['CONTACT_ID']) : 0; if ($entityContactID > 0) { $entityContact = CCrmContact::GetByID($entityContactID); if (is_array($entityContact)) { $item = array('ownerEntityType' => 'DEAL', 'ownerEntityId' => $entityID, 'entityType' => 'CONTACT', 'entityId' => $entityContactID, 'entityTitle' => CUser::FormatName($fullNameFormat, array('LOGIN' => '', 'NAME' => $entityContact['NAME'], 'LAST_NAME' => $entityContact['LAST_NAME'], 'SECOND_NAME' => $entityContact['SECOND_NAME']), false, false), 'tabId' => 'deal', 'communications' => array()); $entityCompany = isset($entityContact['COMPANY_ID']) ? CCrmCompany::GetByID($entityContact['COMPANY_ID']) : null; if ($entityCompany && isset($entityCompany['TITLE'])) { $item['entityDescription'] = $entityCompany['TITLE']; } if ($communicationType !== '') { $entityContactComms = CCrmActivity::PrepareCommunications('CONTACT', $entityContactID, $communicationType); foreach ($entityContactComms as &$entityContactComm) { $comm = array('type' => $entityContactComm['TYPE'], 'value' => $entityContactComm['VALUE']); $item['communications'][] = $comm; } unset($entityContactComm); } if ($communicationType === '' || !empty($item['communications'])) { $dealData["CONTACT_{$entityContactID}"] = $item; } } } if ($entityCompanyData && !empty($entityCompanyData['communications'])) { $dealData['COMPANY_' . $entityCompanyID] = $entityCompanyData; $dealData['COMPANY_' . $entityCompanyID]['tabId'] = 'deal'; } // Try to get previous communications $entityComms = CCrmActivity::GetCommunicationsByOwner('DEAL', $entityID, $communicationType); foreach ($entityComms as &$entityComm) { CCrmActivity::PrepareCommunicationInfo($entityComm); $key = "{$entityComm['ENTITY_TYPE']}_{$entityComm['ENTITY_ID']}"; if (!isset($dealData[$key])) { $dealData[$key] = array('ownerEntityType' => 'DEAL', 'ownerEntityId' => $entityID, 'entityType' => CCrmOwnerType::ResolveName($entityComm['ENTITY_TYPE_ID']), 'entityId' => $entityComm['ENTITY_ID'], 'entityTitle' => isset($entityComm['TITLE']) ? $entityComm['TITLE'] : '', 'entityDescription' => isset($entityComm['DESCRIPTION']) ? $entityComm['DESCRIPTION'] : '', 'tabId' => 'deal', 'communications' => array()); } if ($communicationType !== '') { $commFound = false; foreach ($dealData[$key]['communications'] as &$comm) { if ($comm['value'] === $entityComm['VALUE']) { $commFound = true; break; } } unset($comm); if ($commFound) { continue; } $comm = array('type' => $entityComm['TYPE'], 'value' => $entityComm['VALUE']); $dealData[$key]['communications'][] = $comm; } } unset($entityComm); $companyData = array(); // Try to get contacts of company if ($entityCompany > 0) { $entityComms = CCrmActivity::GetCompanyCommunications($entityCompanyID, $communicationType); foreach ($entityComms as &$entityComm) { CCrmActivity::PrepareCommunicationInfo($entityComm); $key = "{$entityComm['ENTITY_TYPE']}_{$entityComm['ENTITY_ID']}"; if (!isset($companyData[$key])) { $companyData[$key] = array('ownerEntityType' => 'DEAL', 'ownerEntityId' => $entityID, 'entityType' => CCrmOwnerType::ResolveName($entityComm['ENTITY_TYPE_ID']), 'entityId' => $entityComm['ENTITY_ID'], 'entityTitle' => isset($entityComm['TITLE']) ? $entityComm['TITLE'] : '', 'entityDescription' => isset($entityComm['DESCRIPTION']) ? $entityComm['DESCRIPTION'] : '', 'tabId' => 'company', 'communications' => array()); } if ($communicationType !== '') { $comm = array('type' => $entityComm['TYPE'], 'value' => $entityComm['VALUE']); $companyData[$key]['communications'][] = $comm; } } unset($entityComm); } if ($entityCompanyData && !empty($entityCompanyData['communications'])) { $companyData['COMPANY_' . $entityCompanyID] = $entityCompanyData; $companyData['COMPANY_' . $entityCompanyID]['tabId'] = 'company'; } return array('DATA' => array('TABS' => array(array('id' => 'deal', 'title' => GetMessage('CRM_COMMUNICATION_TAB_DEAL'), 'active' => true, 'items' => array_values($dealData)), array('id' => 'company', 'title' => GetMessage('CRM_COMMUNICATION_TAB_COMPANY'), 'items' => array_values($companyData))))); } elseif ($entityType === 'COMPANY') { $companyData = array(); $entity = CCrmCompany::GetByID($entityID); if (!$entity) { return array('ERROR' => 'Invalid data'); } $companyItem = array('ownerEntityType' => 'COMPANY', 'ownerEntityId' => $entityID, 'entityType' => 'COMPANY', 'entityId' => $entityID, 'entityTitle' => isset($entity['TITLE']) ? $entity['TITLE'] : "{$entityType}_{$entityID}", 'entityDescription' => '', 'tabId' => 'company', 'communications' => array()); // Try to load entity communications if (!CCrmActivity::CheckReadPermission(CCrmOwnerType::ResolveID($entityType), $entityID)) { return array('ERROR' => GetMessage('CRM_PERMISSION_DENIED')); } if ($communicationType !== '') { $dbResFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => $entityType, 'ELEMENT_ID' => $entityID, 'TYPE_ID' => $communicationType)); while ($arField = $dbResFields->Fetch()) { if (empty($arField['VALUE'])) { continue; } $comm = array('type' => $communicationType, 'value' => $arField['VALUE']); $companyItem['communications'][] = $comm; } } $companyData["{$entityType}_{$entityID}"] = $companyItem; if ($communicationType !== '') { $entityComms = CCrmActivity::GetCompanyCommunications($entityID, $communicationType, 50); foreach ($entityComms as &$entityComm) { CCrmActivity::PrepareCommunicationInfo($entityComm); $key = "{$entityComm['ENTITY_TYPE']}_{$entityComm['ENTITY_ID']}"; if (!isset($companyData[$key])) { $companyData[$key] = array('ownerEntityType' => 'COMPANY', 'ownerEntityId' => $entityID, 'entityType' => $entityComm['ENTITY_TYPE'], 'entityId' => $entityComm['ENTITY_ID'], 'entityTitle' => isset($entityComm['TITLE']) ? $entityComm['TITLE'] : '', 'entityDescription' => isset($entityComm['DESCRIPTION']) ? $entityComm['DESCRIPTION'] : '', 'tabId' => 'company', 'communications' => array()); } $comm = array('type' => $entityComm['TYPE'], 'value' => $entityComm['VALUE']); $companyData[$key]['communications'][] = $comm; } unset($entityComm); } return array('DATA' => array('TABS' => array(array('id' => 'company', 'title' => GetMessage('CRM_COMMUNICATION_TAB_COMPANY'), 'active' => true, 'items' => array_values($companyData))))); } elseif ($entityType === 'CONTACT') { $contactData = array(); $entity = CCrmContact::GetByID($entityID); if (!$entity) { return array('ERROR' => 'Invalid data'); } $entityCompany = isset($entity['COMPANY_ID']) ? CCrmCompany::GetByID($entity['COMPANY_ID']) : null; $contactItem = array('ownerEntityType' => 'CONTACT', 'ownerEntityId' => $entityID, 'entityType' => 'CONTACT', 'entityId' => $entityID, 'entityTitle' => CUser::FormatName($fullNameFormat, array('LOGIN' => '', 'NAME' => $entity['NAME'], 'LAST_NAME' => $entity['LAST_NAME'], 'SECOND_NAME' => $entity['SECOND_NAME']), false, false), 'entityDescription' => $entityCompany && isset($entityCompany['TITLE']) ? $entityCompany['TITLE'] : '', 'tabId' => 'contact', 'communications' => array()); // Try to load entity communications if (!CCrmActivity::CheckReadPermission(CCrmOwnerType::ResolveID($entityType), $entityID)) { return array('ERROR' => GetMessage('CRM_PERMISSION_DENIED')); } if ($communicationType !== '') { $dbResFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => $entityType, 'ELEMENT_ID' => $entityID, 'TYPE_ID' => $communicationType)); while ($arField = $dbResFields->Fetch()) { if (empty($arField['VALUE'])) { continue; } $comm = array('type' => $communicationType, 'value' => $arField['VALUE']); $contactItem['communications'][] = $comm; } } $contactData["{$entityType}_{$entityID}"] = $contactItem; return array('DATA' => array('TABS' => array(array('id' => 'contact', 'title' => GetMessage('CRM_COMMUNICATION_TAB_CONTACT'), 'active' => true, 'items' => array_values($contactData))))); } return array('ERROR' => 'Invalid data'); }
$item['COMMUNICATIONS'][] = array('TYPE' => $result['TYPE'], 'VALUE' => $result['VALUE']); } if (!isset($imageless[$entityTypeName])) { $imageless[$entityTypeName] = array(); } $imageless[$entityTypeName][] = $entityID; $items["{$entityTypeName}_{$entityID}"] =& $item; unset($item); } unset($result); } elseif ($ownerTypeID === CCrmOwnerType::Lead) { if (!CCrmActivity::CheckReadPermission(CCrmOwnerType::Lead, $ownerID)) { ShowError(GetMessage('CRM_PERMISSION_DENIED')); return; } $entity = CCrmLead::GetByID($ownerID, false); if (!is_array($entity)) { ShowError(GetMessage('M_CRM_COMM_SELECTOR_OWNER_NOT_FOUND')); return; } $info = array('ENTITY_TYPE_ID' => CCrmOwnerType::Lead, 'ENTITY_ID' => $ownerID); if (CCrmActivity::PrepareCommunicationInfo($info)) { $item = array('OWNER_ID' => $ownerID, 'OWNER_TYPE_ID' => CCrmOwnerType::Lead, 'TITLE' => $info['TITLE'], 'DESCRIPTION' => $info['DESCRIPTION'], 'IMAGE_URL' => CCrmMobileHelper::GetLeadListImageStub(), 'COMMUNICATIONS' => array()); if ($commType !== 'PERSON') { $dbMultiFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => CCrmOwnerType::LeadName, 'ELEMENT_ID' => $ownerID, 'TYPE_ID' => $commType)); while ($multiField = $dbMultiFields->Fetch()) { if (empty($multiField['VALUE'])) { continue; } $item['COMMUNICATIONS'][] = array('TYPE' => $commType, 'VALUE' => $multiField['VALUE']); }
public static function CalculateTotalInfo($ownerType, $ownerID, $checkPerms = true, $params = null, $rows = null, $totalInfo = array()) { if (!is_array($totalInfo)) { $totalInfo = array(); } $result = false; if (isset($totalInfo['OPPORTUNITY']) && isset($totalInfo['TAX_VALUE'])) { $result = array('OPPORTUNITY' => round(doubleval($totalInfo['OPPORTUNITY']), 2), 'TAX_VALUE' => round(doubleval($totalInfo['TAX_VALUE']), 2)); } else { $arParams = null; if ($ownerID <= 0) { $arParams = $params; } else { if ($ownerType === 'L') { $arParams = CCrmLead::GetByID($ownerID, $checkPerms); } elseif ($ownerType === 'D') { $arParams = CCrmDeal::GetByID($ownerID, $checkPerms); } elseif ($ownerType === CCrmQuote::OWNER_TYPE) { $arParams = CCrmQuote::GetByID($ownerID, $checkPerms); } } if (!is_array($arParams)) { return $result; } $arRows = null; if (is_array($rows)) { $arRows = $rows; } elseif ($ownerID > 0) { $arRows = CCrmProductRow::LoadRows($ownerType, $ownerID); } if (!is_array($arRows)) { return $result; } $currencyID = isset($params['CURRENCY_ID']) ? $params['CURRENCY_ID'] : ''; if ($currencyID === '') { $currencyID = CCrmCurrency::GetBaseCurrencyID(); } $companyID = isset($params['COMPANY_ID']) ? intval($params['COMPANY_ID']) : 0; $contactID = isset($params['CONTACT_ID']) ? intval($params['CONTACT_ID']) : 0; // Determine person type $personTypeId = 0; $arPersonTypes = CCrmPaySystem::getPersonTypeIDs(); if ($companyID > 0 && isset($arPersonTypes['COMPANY'])) { $personTypeId = $arPersonTypes['COMPANY']; } elseif ($contactID > 0 && isset($arPersonTypes['CONTACT'])) { $personTypeId = $arPersonTypes['CONTACT']; } $enableSaleDiscount = false; $siteID = ''; if (defined('SITE_ID')) { $siteID = SITE_ID; } else { $obSite = CSite::GetList($by = 'def', $order = 'desc', array('ACTIVE' => 'Y')); if ($obSite && ($arSite = $obSite->Fetch())) { $siteID = $arSite["LID"]; } unset($obSite, $arSite); } $calculateOptions = array(); if (CCrmTax::isTaxMode()) { $calculateOptions['LOCATION_ID'] = isset($arParams['LOCATION_ID']) ? $arParams['LOCATION_ID'] : ''; } $calculated = CCrmSaleHelper::Calculate($arRows, $currencyID, $personTypeId, $enableSaleDiscount, $siteID, $calculateOptions); $result = array('OPPORTUNITY' => isset($calculated['PRICE']) ? round(doubleval($calculated['PRICE']), 2) : 1.0, 'TAX_VALUE' => isset($calculated['TAX_VALUE']) ? round(doubleval($calculated['TAX_VALUE']), 2) : 0.0); } return $result; }
private static function TryInternalizeCrmEntityID($type, $value, &$ID) { if (preg_match('/^\\[([A-Z]+)\\]/i', $value, $m) > 0) { $valueType = CCrmOwnerType::Undefined; $prefix = strtoupper($m[1]); if ($prefix === 'L') { $valueType = CCrmOwnerType::Lead; } elseif ($prefix === 'C') { $valueType = CCrmOwnerType::Contact; } elseif ($prefix === 'CO') { $valueType = CCrmOwnerType::Company; } elseif ($prefix === 'D') { $valueType = CCrmOwnerType::Deal; } if ($valueType !== CCrmOwnerType::Undefined && $valueType !== $type) { return false; } $value = substr($value, strlen($m[0])); } // 1. Try to interpret data as entity ID // 2. Try to interpret data as entity name if ($type === CCrmOwnerType::Lead) { if (is_numeric($value)) { $arEntity = CCrmLead::GetByID($value); if ($arEntity) { $ID = intval($arEntity['ID']); return true; } } $rsEntities = CCrmLead::GetList(array(), array('=TITLE' => $value), array('ID')); while ($arEntity = $rsEntities->Fetch()) { $ID = intval($arEntity['ID']); return true; } } elseif ($type === CCrmOwnerType::Contact) { if (is_numeric($value)) { $arEntity = CCrmContact::GetByID($value); if ($arEntity) { $ID = intval($arEntity['ID']); return true; } } // Try to interpret value as FULL_NAME $rsEntities = CCrmContact::GetListEx(array(), array('=FULL_NAME' => $value), false, false, array('ID')); while ($arEntity = $rsEntities->Fetch()) { $ID = intval($arEntity['ID']); return true; } if (preg_match('/\\s*([^\\s]+)\\s+([^\\s]+)\\s*/', $value, $match) > 0) { // Try to interpret value as '#NAME# #LAST_NAME#' $rsEntities = CCrmContact::GetListEx(array(), array('=NAME' => $match[1], '=LAST_NAME' => $match[2]), false, false, array('ID')); while ($arEntity = $rsEntities->Fetch()) { $ID = intval($arEntity['ID']); return true; } // Try to interpret value as '#LAST_NAME# #NAME#' $rsEntities = CCrmContact::GetListEx(array(), array('=LAST_NAME' => $match[1], '=NAME' => $match[2]), false, false, array('ID')); while ($arEntity = $rsEntities->Fetch()) { $ID = intval($arEntity['ID']); return true; } } else { // Try to interpret value as '#LAST_NAME#' $rsEntities = CCrmContact::GetListEx(array(), array('=LAST_NAME' => $value), false, false, array('ID')); while ($arEntity = $rsEntities->Fetch()) { $ID = intval($arEntity['ID']); return true; } } } elseif ($type === CCrmOwnerType::Company) { if (is_numeric($value)) { $arEntity = CCrmCompany::GetByID($value); if ($arEntity) { $ID = intval($arEntity['ID']); return true; } } $rsEntities = CCrmCompany::GetList(array(), array('=TITLE' => $value), array('ID')); while ($arEntity = $rsEntities->Fetch()) { $ID = intval($arEntity['ID']); return true; } } elseif ($type === CCrmOwnerType::Deal) { if (is_numeric($value)) { $arEntity = CCrmDeal::GetByID($value); if ($arEntity) { $ID = intval($arEntity['ID']); return true; } } $rsEntities = CCrmDeal::GetList(array(), array('=TITLE' => $value), array('ID')); while ($arEntity = $rsEntities->Fetch()) { $ID = intval($arEntity['ID']); return true; } } return false; }