Example #1
0
 public static function Delete($ID, $checkPerms = true, $regEvent = true, $options = array())
 {
     $ID = intval($ID);
     if (!is_array($options)) {
         $options = array();
     }
     $events = GetModuleEvents('crm', 'OnBeforeActivityDelete');
     while ($event = $events->Fetch()) {
         if (ExecuteModuleEventEx($event, array($ID)) === false) {
             return false;
         }
     }
     $ary = isset($options['ACTUAL_ITEM']) && is_array($options['ACTUAL_ITEM']) ? $options['ACTUAL_ITEM'] : self::GetByID($ID, $checkPerms);
     if (!is_array($ary)) {
         return false;
         //is not found
     }
     $arBindings = isset($options['ACTUAL_BINDINGS']) && is_array($options['ACTUAL_BINDINGS']) ? $options['ACTUAL_BINDINGS'] : self::GetBindings($ID);
     if (!self::InnerDelete($ID, $options)) {
         return false;
     }
     self::UnregisterLiveFeedEvent($ID);
     CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Activity, $ID);
     // Synchronize user activity -->
     $skipUserActivitySync = isset($options['SKIP_USER_ACTIVITY_SYNC']) ? $options['SKIP_USER_ACTIVITY_SYNC'] : false;
     if (!$skipUserActivitySync) {
         $responsibleID = isset($ary['RESPONSIBLE_ID']) ? intval($ary['RESPONSIBLE_ID']) : 0;
         if ($responsibleID > 0 && is_array($arBindings)) {
             foreach ($arBindings as &$arBinding) {
                 self::SynchronizeUserActivity($arBinding['OWNER_TYPE_ID'], $arBinding['OWNER_ID'], $responsibleID);
                 self::SynchronizeUserActivity($arBinding['OWNER_TYPE_ID'], $arBinding['OWNER_ID'], 0);
             }
             unset($arBinding);
         }
     }
     // <-- Synchronize user activity
     if (is_array($arBindings)) {
         if ($regEvent) {
             foreach ($arBindings as &$arBinding) {
                 self::RegisterRemoveEvent($arBinding['OWNER_TYPE_ID'], $arBinding['OWNER_ID'], $ary, $checkPerms);
             }
             unset($arBinding);
         }
         $skipStatistics = isset($options['SKIP_STATISTICS']) ? $options['SKIP_STATISTICS'] : false;
         if (!$skipStatistics) {
             $completed = isset($ary['COMPLETED']) && $ary['COMPLETED'] === 'Y';
             $deadline = isset($ary['DEADLINE']) ? $ary['DEADLINE'] : '';
             if ($completed && $deadline) {
                 $deadline = new \Bitrix\Main\Type\DateTime($deadline);
                 $deadline->setTime(0, 0, 0);
                 foreach ($arBindings as &$arBinding) {
                     $curOwnerTypeID = isset($arBinding['OWNER_TYPE_ID']) ? intval($arBinding['OWNER_TYPE_ID']) : 0;
                     $curOwnerID = isset($arBinding['OWNER_ID']) ? intval($arBinding['OWNER_ID']) : 0;
                     if ($curOwnerTypeID === CCrmOwnerType::Deal && $curOwnerID > 0) {
                         Bitrix\Crm\Statistics\DealActivityStatisticEntry::register($curOwnerID, null, array('DATE' => $deadline));
                     }
                 }
                 unset($arBinding);
             }
         }
     }
     $skipAssocEntity = isset($options['SKIP_ASSOCIATED_ENTITY']) ? (bool) $options['SKIP_ASSOCIATED_ENTITY'] : false;
     if (!$skipAssocEntity && isset($ary['TYPE_ID']) && isset($ary['ASSOCIATED_ENTITY_ID'])) {
         switch (intval($ary['TYPE_ID'])) {
             case CCrmActivityType::Call:
             case CCrmActivityType::Meeting:
                 self::DeleteCalendarEvent($ary);
                 break;
             case CCrmActivityType::Task:
                 self::DeleteTask($ary);
                 break;
             case CCrmActivityType::Email:
                 //do nothing
                 break;
         }
     }
     $rsEvents = GetModuleEvents('crm', 'OnActivityDelete');
     while ($arEvent = $rsEvents->Fetch()) {
         ExecuteModuleEventEx($arEvent, array($ID));
     }
     if (defined("BX_COMP_MANAGED_CACHE")) {
         $GLOBALS["CACHE_MANAGER"]->ClearByTag("CRM_ACTIVITY_" . $ID);
     }
     return true;
 }
Example #2
0
 public function Delete($ID, $arOptions = array())
 {
     global $DB, $APPLICATION;
     $ID = intval($ID);
     $iUserId = CCrmSecurityHelper::GetCurrentUserID();
     if (!is_array($arOptions)) {
         $arOptions = array();
     }
     $sWherePerm = '';
     if ($this->bCheckPermission) {
         $arEntityAttr = $this->cPerms->GetEntityAttr('DEAL', $ID);
         $sEntityPerm = $this->cPerms->GetPermType('DEAL', 'DELETE', $arEntityAttr[$ID]);
         if ($sEntityPerm == BX_CRM_PERM_NONE) {
             return false;
         } else {
             if ($sEntityPerm == BX_CRM_PERM_SELF) {
                 $sWherePerm = " AND ASSIGNED_BY_ID = {$iUserId}";
             } else {
                 if ($sEntityPerm == BX_CRM_PERM_OPEN) {
                     $sWherePerm = " AND (OPENED = 'Y' OR ASSIGNED_BY_ID = {$iUserId})";
                 }
             }
         }
     }
     $APPLICATION->ResetException();
     $events = GetModuleEvents('crm', 'OnBeforeCrmDealDelete');
     while ($arEvent = $events->Fetch()) {
         if (ExecuteModuleEventEx($arEvent, array($ID)) === false) {
             $err = GetMessage("MAIN_BEFORE_DEL_ERR") . ' ' . $arEvent['TO_NAME'];
             if ($ex = $APPLICATION->GetException()) {
                 $err .= ': ' . $ex->GetString();
             }
             $APPLICATION->throwException($err);
             return false;
         }
     }
     //By defaut we need to clean up related bizproc entities
     $processBizproc = isset($arOptions['PROCESS_BIZPROC']) ? (bool) $arOptions['PROCESS_BIZPROC'] : true;
     if ($processBizproc) {
         $bizproc = new CCrmBizProc('DEAL');
         $bizproc->ProcessDeletion($ID);
     }
     $dbRes = $DB->Query("DELETE FROM b_crm_deal WHERE ID = {$ID}{$sWherePerm}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
     if (is_object($dbRes) && $dbRes->AffectedRowsCount() > 0) {
         CCrmSearch::DeleteSearch('DEAL', $ID);
         $DB->Query("DELETE FROM b_crm_entity_perms WHERE ENTITY='DEAL' AND ENTITY_ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
         $GLOBALS['USER_FIELD_MANAGER']->Delete(self::$sUFEntityID, $ID);
         $CCrmFieldMulti = new CCrmFieldMulti();
         $CCrmFieldMulti->DeleteByElement('DEAL', $ID);
         $CCrmEvent = new CCrmEvent();
         $CCrmEvent->DeleteByElement('DEAL', $ID);
         Bitrix\Crm\History\DealStageHistoryEntry::unregister($ID);
         Bitrix\Crm\Statistics\DealSumStatisticEntry::unregister($ID);
         Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::unregister($ID);
         Bitrix\Crm\Statistics\DealActivityStatisticEntry::unregister($ID);
         // Deletion of deal details
         CCrmProductRow::DeleteByOwner('D', $ID);
         CCrmProductRow::DeleteSettings('D', $ID);
         CCrmActivity::DeleteByOwner(CCrmOwnerType::Deal, $ID);
         CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Deal, $ID);
         CCrmLiveFeed::DeleteLogEvents(array('ENTITY_TYPE_ID' => CCrmOwnerType::Deal, 'ENTITY_ID' => $ID));
         self::PullChange('DELETE', array('ID' => $ID));
         if (defined("BX_COMP_MANAGED_CACHE")) {
             $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Deal . "_" . $ID);
         }
         $afterEvents = GetModuleEvents('crm', 'OnAfterCrmDealDelete');
         while ($arEvent = $afterEvents->Fetch()) {
             ExecuteModuleEventEx($arEvent, array($ID));
         }
     }
     return true;
 }
Example #3
0
    if ($bImport) {
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('DEAL_IMPORT'), 'TITLE' => GetMessage('DEAL_IMPORT_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_DEAL_IMPORT'], array()), 'ICON' => 'btn-import');
    }
    if ($bExport) {
        $arResult['BUTTONS'][] = array('TITLE' => GetMessage('DEAL_EXPORT_CSV_TITLE'), 'TEXT' => GetMessage('DEAL_EXPORT_CSV'), 'LINK' => CHTTP::urlAddParams(CComponentEngine::MakePathFromTemplate($APPLICATION->GetCurPage(), array()), array('type' => 'csv', 'ncc' => '1')), 'ICON' => 'btn-export');
        $arResult['BUTTONS'][] = array('TITLE' => GetMessage('DEAL_EXPORT_EXCEL_TITLE'), 'TEXT' => GetMessage('DEAL_EXPORT_EXCEL'), 'LINK' => CHTTP::urlAddParams(CComponentEngine::MakePathFromTemplate($APPLICATION->GetCurPage(), array()), array('type' => 'excel', 'ncc' => '1')), 'ICON' => 'btn-export');
    }
    if (count($arResult['BUTTONS']) > 1) {
        //Force start new bar after first button
        array_splice($arResult['BUTTONS'], 1, 0, array(array('NEWBAR' => true)));
    }
    $this->IncludeComponentTemplate();
    return;
}
if ($arParams['TYPE'] == 'show' && $bRead && $arParams['ELEMENT_ID'] > 0) {
    $subscrTypes = CCrmSonetSubscription::GetRegistationTypes(CCrmOwnerType::Deal, $arParams['ELEMENT_ID'], $currentUserID);
    $isResponsible = in_array(CCrmSonetSubscriptionType::Responsibility, $subscrTypes, true);
    if (!$isResponsible) {
        $subscriptionID = 'deal_sl_subscribe';
        $arResult['SONET_SUBSCRIBE'] = array('ID' => $subscriptionID, 'SERVICE_URL' => CComponentEngine::makePathFromTemplate('#SITE_DIR#bitrix/components/bitrix/crm.deal.edit/ajax.php?site_id=#SITE#&sessid=#SID#', array('SID' => bitrix_sessid())), 'ACTION_NAME' => 'ENABLE_SONET_SUBSCRIPTION', 'RELOAD' => true);
        $isObserver = in_array(CCrmSonetSubscriptionType::Observation, $subscrTypes, true);
        $arResult['BUTTONS'][] = array('CODE' => 'sl_unsubscribe', 'TEXT' => GetMessage('CRM_DEAL_SL_UNSUBSCRIBE'), 'TITLE' => GetMessage('CRM_DEAL_SL_UNSUBSCRIBE_TITLE'), 'ONCLICK' => "BX.CrmSonetSubscription.items['{$subscriptionID}'].unsubscribe({$arParams['ELEMENT_ID']}, function(){ var tb = BX.InterfaceToolBar.items['{$toolbarID}']; tb.setButtonVisible('sl_unsubscribe', false); tb.setButtonVisible('sl_subscribe', true); })", 'ICON' => 'btn-nofollow', 'VISIBLE' => $isObserver);
        $arResult['BUTTONS'][] = array('CODE' => 'sl_subscribe', 'TEXT' => GetMessage('CRM_DEAL_SL_SUBSCRIBE'), 'TITLE' => GetMessage('CRM_DEAL_SL_SUBSCRIBE_TITLE'), 'ONCLICK' => "BX.CrmSonetSubscription.items['{$subscriptionID}'].subscribe({$arParams['ELEMENT_ID']}, function(){ var tb = BX.InterfaceToolBar.items['{$toolbarID}']; tb.setButtonVisible('sl_subscribe', false); tb.setButtonVisible('sl_unsubscribe', true); })", 'ICON' => 'btn-follow', 'VISIBLE' => !$isObserver);
    }
}
if ($arParams['TYPE'] == 'show' && !empty($arParams['ELEMENT_ID'])) {
    if ($bWrite) {
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('DEAL_EDIT'), 'TITLE' => GetMessage('DEAL_EDIT_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_DEAL_EDIT'], array('deal_id' => $arParams['ELEMENT_ID'])), 'ICON' => 'btn-edit');
    }
}
if ($arParams['TYPE'] == 'edit' && $bRead && !empty($arParams['ELEMENT_ID'])) {
Example #4
0
        echo CUtil::PhpToJSObject(array('DATA' => $data, 'INFO' => array('title' => $info['TITLE'], 'url' => $info['URL'])));
    } else {
        echo CUtil::PhpToJSObject(array('ERROR' => $CrmCompany->LAST_ERROR));
    }
} elseif ($action === 'ENABLE_SONET_SUBSCRIPTION') {
    $userID = CCrmSecurityHelper::GetCurrentUserID();
    $entityTypeName = isset($_POST['ENTITY_TYPE']) ? strtoupper($_POST['ENTITY_TYPE']) : '';
    $entityID = isset($_POST['ENTITY_ID']) ? intval($_POST['ENTITY_ID']) : 0;
    if ($userID > 0 && $entityTypeName === CCrmOwnerType::CompanyName && $entityID > 0 && CCrmCompany::CheckReadPermission($entityID)) {
        $isEnabled = CCrmSonetSubscription::IsRelationRegistered(CCrmOwnerType::Company, $entityID, CCrmSonetSubscriptionType::Observation, $userID);
        $enable = isset($_POST['ENABLE']) && strtoupper($_POST['ENABLE']) === 'Y';
        if ($isEnabled !== $enable) {
            if ($enable) {
                CCrmSonetSubscription::RegisterSubscription(CCrmOwnerType::Company, $entityID, CCrmSonetSubscriptionType::Observation, $userID);
            } else {
                CCrmSonetSubscription::UnRegisterSubscription(CCrmOwnerType::Company, $entityID, CCrmSonetSubscriptionType::Observation, $userID);
            }
        }
    }
} elseif ($action === 'FIND_DUPLICATES') {
    $userPermissions = CCrmPerms::GetCurrentUserPermissions();
    $params = isset($_POST['PARAMS']) && is_array($_POST['PARAMS']) ? $_POST['PARAMS'] : array();
    $entityTypeName = isset($params['ENTITY_TYPE_NAME']) ? $params['ENTITY_TYPE_NAME'] : '';
    if ($entityTypeName === '') {
        __CrmCompanyEditEndResonse(array('ERROR' => 'Entity type is not specified.'));
    }
    $entityTypeID = CCrmOwnerType::ResolveID($entityTypeName);
    if ($entityTypeID === CCrmOwnerType::Undefined) {
        __CrmCompanyEditEndResonse(array('ERROR' => 'Undefined entity type is specified.'));
    }
    if ($entityTypeID !== CCrmOwnerType::Company) {
Example #5
0
 public function Delete($ID, $arOptions = array())
 {
     global $DB, $APPLICATION;
     $ID = intval($ID);
     $iUserId = CCrmSecurityHelper::GetCurrentUserID();
     $this->LAST_ERROR = '';
     $APPLICATION->ResetException();
     if (!is_array($arOptions)) {
         $arOptions = array();
     }
     if (isset($arOptions['CHECK_DEPENDENCIES']) && (bool) $arOptions['CHECK_DEPENDENCIES']) {
         $dbRes = self::GetListEx(array(), array('=ID' => $ID), false, false, array('TITLE', 'STATUS_ID', 'COMPANY_ID', 'CONTACT_ID'));
         $arFields = $dbRes ? $dbRes->Fetch() : null;
         if (is_array($arFields) && isset($arFields['STATUS_ID']) && $arFields['STATUS_ID'] === 'CONVERTED' && (CCrmCompany::Exists(isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0) || CCrmContact::Exists(isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : 0))) {
             $title = isset($arFields['TITLE']) && $arFields['TITLE'] !== '' ? $arFields['TITLE'] : $ID;
             $err = GetMessage('CRM_LEAD_DELETION_DEPENDENCIES_FOUND', array('#TITLE#' => $title));
             $this->LAST_ERROR = $err;
             $APPLICATION->throwException($err);
             return false;
         }
     }
     $sWherePerm = '';
     if ($this->bCheckPermission) {
         $arEntityAttr = $this->cPerms->GetEntityAttr('LEAD', $ID);
         $sEntityPerm = $this->cPerms->GetPermType('LEAD', 'DELETE', $arEntityAttr[$ID]);
         if ($sEntityPerm == BX_CRM_PERM_NONE) {
             return false;
         } else {
             if ($sEntityPerm == BX_CRM_PERM_SELF) {
                 $sWherePerm = " AND ASSIGNED_BY_ID = {$iUserId}";
             } else {
                 if ($sEntityPerm == BX_CRM_PERM_OPEN) {
                     $sWherePerm = " AND (OPENED = 'Y' OR ASSIGNED_BY_ID = {$iUserId})";
                 }
             }
         }
     }
     $events = GetModuleEvents('crm', 'OnBeforeCrmLeadDelete');
     while ($arEvent = $events->Fetch()) {
         if (ExecuteModuleEventEx($arEvent, array($ID)) === false) {
             $err = GetMessage("MAIN_BEFORE_DEL_ERR") . ' ' . $arEvent['TO_NAME'];
             if ($ex = $APPLICATION->GetException()) {
                 $err .= ': ' . $ex->GetString();
             }
             $APPLICATION->throwException($err);
             $this->LAST_ERROR = $err;
             return false;
         }
     }
     //By defaut we need to clean up related bizproc entities
     $processBizproc = isset($arOptions['PROCESS_BIZPROC']) ? (bool) $arOptions['PROCESS_BIZPROC'] : true;
     if ($processBizproc) {
         $bizproc = new CCrmBizProc('LEAD');
         $bizproc->ProcessDeletion($ID);
     }
     $tableName = CCrmLead::TABLE_NAME;
     $sSql = "DELETE FROM {$tableName} WHERE ID = {$ID}{$sWherePerm}";
     $obRes = $DB->Query($sSql, false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
     if (is_object($obRes) && $obRes->AffectedRowsCount() > 0) {
         CCrmSearch::DeleteSearch('LEAD', $ID);
         $DB->Query("DELETE FROM b_crm_entity_perms WHERE ENTITY='LEAD' AND ENTITY_ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
         $GLOBALS['USER_FIELD_MANAGER']->Delete(self::$sUFEntityID, $ID);
         $CCrmFieldMulti = new CCrmFieldMulti();
         $CCrmFieldMulti->DeleteByElement('LEAD', $ID);
         $CCrmEvent = new CCrmEvent();
         $CCrmEvent->DeleteByElement('LEAD', $ID);
         \Bitrix\Crm\EntityAddress::unregister(CCrmOwnerType::Lead, $ID, \Bitrix\Crm\EntityAddress::Primary);
         \Bitrix\Crm\Integrity\DuplicateEntityRanking::unregisterEntityStatistics(CCrmOwnerType::Lead, $ID);
         \Bitrix\Crm\Integrity\DuplicatePersonCriterion::unregister(CCrmOwnerType::Lead, $ID);
         \Bitrix\Crm\Integrity\DuplicateOrganizationCriterion::unregister(CCrmOwnerType::Lead, $ID);
         \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::unregister(CCrmOwnerType::Lead, $ID);
         \Bitrix\Crm\Integrity\DuplicateIndexMismatch::unregisterEntity(CCrmOwnerType::Lead, $ID);
         $enableDupIndexInvalidation = is_array($arOptions) && isset($arOptions['ENABLE_DUP_INDEX_INVALIDATION']) ? (bool) $arOptions['ENABLE_DUP_INDEX_INVALIDATION'] : true;
         if ($enableDupIndexInvalidation) {
             \Bitrix\Crm\Integrity\DuplicateIndexBuilder::markAsJunk(CCrmOwnerType::Lead, $ID);
         }
         // Deletion of lead details
         CCrmProductRow::DeleteByOwner('L', $ID);
         CCrmProductRow::DeleteSettings('L', $ID);
         CCrmActivity::DeleteByOwner(CCrmOwnerType::Lead, $ID);
         CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Lead, $ID);
         CCrmLiveFeed::DeleteLogEvents(array('ENTITY_TYPE_ID' => CCrmOwnerType::Lead, 'ENTITY_ID' => $ID));
         if (defined("BX_COMP_MANAGED_CACHE")) {
             $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Lead . "_" . $ID);
         }
         $afterEvents = GetModuleEvents('crm', 'OnAfterCrmLeadDelete');
         while ($arEvent = $afterEvents->Fetch()) {
             ExecuteModuleEventEx($arEvent, array($ID));
         }
     }
     return true;
 }
Example #6
0
 public function Delete($ID, $arOptions = array())
 {
     global $DB, $APPLICATION;
     $ID = intval($ID);
     $iUserId = CCrmSecurityHelper::GetCurrentUserID();
     $sWherePerm = '';
     if ($this->bCheckPermission) {
         $arEntityAttr = $this->cPerms->GetEntityAttr('COMPANY', $ID);
         $sEntityPerm = $this->cPerms->GetPermType('COMPANY', 'DELETE', $arEntityAttr[$ID]);
         if ($sEntityPerm == BX_CRM_PERM_NONE) {
             return false;
         } else {
             if ($sEntityPerm == BX_CRM_PERM_SELF) {
                 $sWherePerm = " AND ASSIGNED_BY_ID = {$iUserId}";
             } else {
                 if ($sEntityPerm == BX_CRM_PERM_OPEN) {
                     $sWherePerm = " AND (OPENED = 'Y' OR ASSIGNED_BY_ID = {$iUserId})";
                 }
             }
         }
     }
     $APPLICATION->ResetException();
     $events = GetModuleEvents('crm', 'OnBeforeCrmCompanyDelete');
     while ($arEvent = $events->Fetch()) {
         if (ExecuteModuleEventEx($arEvent, array($ID)) === false) {
             $err = GetMessage("MAIN_BEFORE_DEL_ERR") . ' ' . $arEvent['TO_NAME'];
             if ($ex = $APPLICATION->GetException()) {
                 $err .= ': ' . $ex->GetString();
             }
             $APPLICATION->throwException($err);
             return false;
         }
     }
     $obRes = $DB->Query("DELETE FROM b_crm_company WHERE ID = {$ID}{$sWherePerm}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
     if (is_object($obRes) && $obRes->AffectedRowsCount() > 0) {
         $DB->Query("DELETE FROM b_crm_entity_perms WHERE ENTITY='COMPANY' AND ENTITY_ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
         $GLOBALS['USER_FIELD_MANAGER']->Delete(self::$sUFEntityID, $ID);
         $CCrmFieldMulti = new CCrmFieldMulti();
         $CCrmFieldMulti->DeleteByElement('COMPANY', $ID);
         $CCrmEvent = new CCrmEvent();
         $CCrmEvent->DeleteByElement('COMPANY', $ID);
         \Bitrix\Crm\Integrity\DuplicateEntityRanking::unregisterEntityStatistics(CCrmOwnerType::Company, $ID);
         \Bitrix\Crm\Integrity\DuplicateOrganizationCriterion::unregister(CCrmOwnerType::Company, $ID);
         \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::unregister(CCrmOwnerType::Company, $ID);
         \Bitrix\Crm\Integrity\DuplicateIndexMismatch::unregisterEntity(CCrmOwnerType::Company, $ID);
         $enableDupIndexInvalidation = is_array($arOptions) && isset($arOptions['ENABLE_DUP_INDEX_INVALIDATION']) ? (bool) $arOptions['ENABLE_DUP_INDEX_INVALIDATION'] : true;
         if ($enableDupIndexInvalidation) {
             \Bitrix\Crm\Integrity\DuplicateIndexBuilder::markAsJunk(CCrmOwnerType::Company, $ID);
         }
         CCrmActivity::DeleteByOwner(CCrmOwnerType::Company, $ID);
         CCrmSearch::DeleteSearch('COMPANY', $ID);
         CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Company, $ID);
         CCrmLiveFeed::DeleteLogEvents(array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $ID));
         if (defined("BX_COMP_MANAGED_CACHE")) {
             $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Company . "_" . $ID);
         }
     }
     return true;
 }
Example #7
0
 public function Delete($ID)
 {
     /** @global CUserTypeManager $USER_FIELD_MANAGER */
     global $USER_FIELD_MANAGER;
     if (!CModule::IncludeModule('sale')) {
         return false;
     }
     $dealID = 0;
     $dbResult = CCrmInvoice::GetList(array(), array('ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'UF_DEAL_ID'));
     $fields = is_object($dbResult) ? $dbResult->Fetch() : null;
     if (is_array($fields)) {
         $dealID = isset($fields['UF_DEAL_ID']) ? $fields['UF_DEAL_ID'] : 0;
     }
     $CSaleOrder = new CSaleOrder();
     $result = $CSaleOrder->Delete($ID);
     if ($result) {
         $USER_FIELD_MANAGER->Delete(self::$sUFEntityID, $ID);
         CCrmProductRow::DeleteSettings('I', $ID);
         self::UnregisterLiveFeedEvent($ID);
         CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Invoice, $ID);
         if ($dealID > 0) {
             Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::register($dealID);
         }
         CCrmSearch::DeleteSearch('INVOICE', $ID);
     }
     return $result;
 }
Example #8
0
 public function Delete($ID)
 {
     /** @global CUserTypeManager $USER_FIELD_MANAGER */
     /** @global CMain $APPLICATION */
     /** @var CApplicationException $ex */
     global $USER_FIELD_MANAGER, $APPLICATION;
     $APPLICATION->ResetException();
     foreach (GetModuleEvents('crm', 'OnBeforeCrmInvoiceDelete', true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($ID)) === false) {
             $err = GetMessage('CRM_INVOICE_DELETE_CANCELED') . ' ' . $arEvent['TO_NAME'];
             if ($ex = $APPLICATION->GetException()) {
                 $err .= ': ' . $ex->GetString();
             }
             $APPLICATION->throwException($err);
             return false;
         }
     }
     if (!CModule::IncludeModule('sale')) {
         return false;
     }
     $dealID = 0;
     $dbResult = CCrmInvoice::GetList(array(), array('ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'UF_DEAL_ID'));
     $fields = is_object($dbResult) ? $dbResult->Fetch() : null;
     if (is_array($fields)) {
         $dealID = isset($fields['UF_DEAL_ID']) ? $fields['UF_DEAL_ID'] : 0;
     }
     $CSaleOrder = new CSaleOrder();
     $result = $CSaleOrder->Delete($ID);
     if ($result) {
         $USER_FIELD_MANAGER->Delete(self::$sUFEntityID, $ID);
         CCrmProductRow::DeleteSettings('I', $ID);
         self::UnregisterLiveFeedEvent($ID);
         CCrmSonetSubscription::UnRegisterSubscriptionByEntity(CCrmOwnerType::Invoice, $ID);
         if ($dealID > 0) {
             Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::register($dealID);
         }
         CCrmSearch::DeleteSearch('INVOICE', $ID);
         foreach (GetModuleEvents('crm', 'OnAfterCrmInvoiceDelete', true) as $arEvent) {
             ExecuteModuleEventEx($arEvent, array($ID));
         }
     }
     return $result;
 }
 public static function GetRegistationTypes($entityTypeID, $entityID, $userID)
 {
     if (!CCrmOwnerType::IsDefined($entityTypeID)) {
         return array();
     }
     $userID = intval($userID);
     $entityID = intval($entityID);
     if ($userID <= 0 || $entityID <= 0) {
         return array();
     }
     $filter = array('SL_ENTITY_TYPE' => CCrmLiveFeedEntity::GetByEntityTypeID($entityTypeID), 'ENTITY_ID' => $entityID, 'USER_ID' => $userID);
     $dbResult = CCrmSonetSubscription::GetList(array(), $filter, false, false, array('TYPE_ID'));
     if (!is_object($dbResult)) {
         return array();
     }
     $result = array();
     while ($fields = $dbResult->Fetch()) {
         $result[] = intval($fields['TYPE_ID']);
     }
     return $result;
 }
Example #10
0
<?php

require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/header.php";
global $APPLICATION;
IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/intranet/public/crm/stream/index.php");
$APPLICATION->SetTitle(GetMessage("CRM_TITLE"));
$APPLICATION->SetPageProperty("BodyClass", " page-one-column");
if (CModule::IncludeModule("crm") && CCrmPerms::IsAccessEnabled()) {
    $currentUserPerms = CCrmPerms::GetCurrentUserPermissions();
    $canEdit = CCrmLead::CheckUpdatePermission(0, $currentUserPerms) || CCrmContact::CheckUpdatePermission(0, $currentUserPerms) || CCrmCompany::CheckUpdatePermission(0, $currentUserPerms) || CCrmDeal::CheckUpdatePermission(0, $currentUserPerms);
    $APPLICATION->IncludeComponent("bitrix:crm.control_panel", "", array("ID" => "STREAM", "ACTIVE_ITEM_ID" => "STREAM", "PATH_TO_COMPANY_LIST" => "/crm/company/", "PATH_TO_COMPANY_EDIT" => "/crm/company/edit/#company_id#/", "PATH_TO_CONTACT_LIST" => "/crm/contact/", "PATH_TO_CONTACT_EDIT" => "/crm/contact/edit/#contact_id#/", "PATH_TO_DEAL_LIST" => "/crm/deal/", "PATH_TO_DEAL_EDIT" => "/crm/deal/edit/#deal_id#/", "PATH_TO_QUOTE_LIST" => "/crm/quote/", "PATH_TO_QUOTE_EDIT" => "/crm/quote/edit/#quote_id#/", "PATH_TO_INVOICE_LIST" => "/crm/invoice/", "PATH_TO_INVOICE_EDIT" => "/crm/invoice/edit/#invoice_id#/", "PATH_TO_LEAD_LIST" => "/crm/lead/", "PATH_TO_LEAD_EDIT" => "/crm/lead/edit/#lead_id#/", "PATH_TO_REPORT_LIST" => "/crm/reports/report/", "PATH_TO_DEAL_FUNNEL" => "/crm/reports/", "PATH_TO_EVENT_LIST" => "/crm/events/", "PATH_TO_PRODUCT_LIST" => "/crm/product/", "PATH_TO_SETTINGS" => "/crm/configs/", "PATH_TO_SEARCH_PAGE" => "/search/index.php?where=crm"));
    // --> IMPORT RESPONSIBILITY SUBSCRIPTIONS
    $currentUserID = CCrmSecurityHelper::GetCurrentUserID();
    if ($currentUserID > 0) {
        CCrmSonetSubscription::EnsureAllResponsibilityImported($currentUserID);
    }
    // <-- IMPORT RESPONSIBILITY SUBSCRIPTIONS
    $APPLICATION->IncludeComponent("bitrix:crm.entity.livefeed", "", array("DATE_TIME_FORMAT" => "d.m.Y H:i:s", "CAN_EDIT" => $canEdit, "FORM_ID" => "", "PATH_TO_USER_PROFILE" => "/company/personal/user/#user_id#/", "PATH_TO_GROUP" => "/workgroups/group/#group_id#/", "PATH_TO_CONPANY_DEPARTMENT" => "/company/structure.php?set_filter_structure=Y&structure_UF_DEPARTMENT=#ID#"), null, array("HIDE_ICONS" => "Y"));
}
require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/footer.php";