public static function findDealsByPhone($phone) { if (strlen($phone) <= 0) { return false; } if (!CModule::IncludeModule('crm')) { return false; } $deals = array(); $entityTypeIDs = array(CCrmOwnerType::Contact, CCrmOwnerType::Company); foreach ($entityTypeIDs as $entityTypeID) { $results = CCrmDeal::FindByCommunication($entityTypeID, 'PHONE', $phone, false, array('ID', 'TITLE', 'STAGE_ID', 'ASSIGNED_BY_ID', 'COMPANY_ID', 'CONTACT_ID', 'DATE_MODIFY')); foreach ($results as $fields) { if (Bitrix\Crm\PhaseSemantics::isFinal($fields['STAGE_ID'])) { continue; } $entityID = (int) ($entityTypeID === CCrmOwnerType::Company ? $fields['COMPANY_ID'] : $fields['CONTACT_ID']); if ($entityID <= 0) { continue; } $deals[$fields['ID']] = $fields; } } sortByColumn($deals, array('DATE_MODIFY' => array(SORT_DESC))); return $deals; }