public static function GetByID($ID, $checkPerms = true) { $ID = intval($ID); if ($ID <= 0) { return null; } $res = CCrmEntityHelper::GetCached(self::CACHE_NAME, $ID); if (is_array($res)) { return $res; } $filter = array('ID' => $ID); if (!$checkPerms) { $filter['CHECK_PERMISSIONS'] = 'N'; } $dbRes = self::GetList(array(), $filter); if (is_array($res = $dbRes->Fetch())) { CCrmEntityHelper::SetCached(self::CACHE_NAME, $ID, $res); } return $res; }
if (intval($arParams['CONTACT_COUNT']) <= 0) { $arParams['CONTACT_COUNT'] = 20; } $arNavParams = array('nPageSize' => $arParams['CONTACT_COUNT']); $arNavigation = CDBResult::GetNavParams($arNavParams); $CGridOptions = new CCrmGridOptions($arResult['GRID_ID'], $arResult['FILTER_PRESETS']); $arNavParams = $CGridOptions->GetNavParams($arNavParams); $arNavParams['bShowAll'] = false; $arFilter += $CGridOptions->GetFilter($arResult['FILTER']); $USER_FIELD_MANAGER->AdminListAddFilter(CCrmContact::$sUFEntityID, $arFilter); // converts data from filter if (isset($arFilter['FIND_list']) && !empty($arFilter['FIND'])) { $arFilter[strtoupper($arFilter['FIND_list'])] = $arFilter['FIND']; unset($arFilter['FIND_list'], $arFilter['FIND']); } CCrmEntityHelper::PrepareMultiFieldFilter($arFilter); $arImmutableFilters = array('FM', 'ID', 'COMPANY_ID', 'ASSIGNED_BY_ID', 'CREATED_BY_ID', 'MODIFY_BY_ID', 'TYPE_ID', 'SOURCE_ID'); foreach ($arFilter as $k => $v) { if (in_array($k, $arImmutableFilters, true)) { continue; } $arMatch = array(); if ($k === 'ORIGINATOR_ID') { // HACK: build filter by internal entities $arFilter['=ORIGINATOR_ID'] = $v !== '__INTERNAL' ? $v : null; unset($arFilter[$k]); } if ($k === 'ADDRESS' || $k === 'ADDRESS_2' || $k === 'ADDRESS_CITY' || $k === 'ADDRESS_REGION' || $k === 'ADDRESS_PROVINCE' || $k === 'ADDRESS_POSTAL_CODE' || $k === 'ADDRESS_COUNTRY') { $arFilter["=%{$k}"] = "{$v}%"; unset($arFilter[$k]); } elseif (preg_match('/(.*)_from$/i' . BX_UTF_PCRE_MODIFIER, $k, $arMatch)) {
public function Update($ID, array &$arFields, $bCompare = true, $bUpdateSearch = true, $options = array()) { global $DB; $this->LAST_ERROR = ''; $ID = (int) $ID; if (!is_array($options)) { $options = array(); } $arFilterTmp = array('ID' => $ID); if (!$this->bCheckPermission) { $arFilterTmp['CHECK_PERMISSIONS'] = 'N'; } $obRes = self::GetListEx(array(), $arFilterTmp); if (!($arRow = $obRes->Fetch())) { return false; } $iUserId = CCrmSecurityHelper::GetCurrentUserID(); if (isset($arFields['DATE_CREATE'])) { unset($arFields['DATE_CREATE']); } if (isset($arFields['DATE_MODIFY'])) { unset($arFields['DATE_MODIFY']); } $arFields['~DATE_MODIFY'] = $DB->CurrentTimeFunction(); if (!isset($arFields['MODIFY_BY_ID']) || $arFields['MODIFY_BY_ID'] <= 0) { $arFields['MODIFY_BY_ID'] = $iUserId; } if (isset($arFields['ASSIGNED_BY_ID']) && $arFields['ASSIGNED_BY_ID'] <= 0) { unset($arFields['ASSIGNED_BY_ID']); } $assignedByID = (int) (isset($arFields['ASSIGNED_BY_ID']) ? $arFields['ASSIGNED_BY_ID'] : $arRow['ASSIGNED_BY_ID']); $bResult = false; if (!$this->CheckFields($arFields, $ID, $options)) { $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR; } else { if ($this->bCheckPermission && !CCrmAuthorizationHelper::CheckUpdatePermission(self::$TYPE_NAME, $ID, $this->cPerms)) { $this->LAST_ERROR = GetMessage('CRM_PERMISSION_DENIED'); $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR; return false; } $beforeEvents = GetModuleEvents('crm', 'OnBeforeCrmDealUpdate'); while ($arEvent = $beforeEvents->Fetch()) { if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) { if (isset($arFields['RESULT_MESSAGE'])) { $this->LAST_ERROR = $arFields['RESULT_MESSAGE']; } else { $this->LAST_ERROR = GetMessage('CRM_DEAL_UPDATE_CANCELED', array('#NAME#' => $arEvent['TO_NAME'])); $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR; } return false; } } $arAttr = array(); $arAttr['STAGE_ID'] = !empty($arFields['STAGE_ID']) ? $arFields['STAGE_ID'] : $arRow['STAGE_ID']; $arAttr['OPENED'] = !empty($arFields['OPENED']) ? $arFields['OPENED'] : $arRow['OPENED']; $arEntityAttr = self::BuildEntityAttr($assignedByID, $arAttr); $sEntityPerm = $this->cPerms->GetPermType('DEAL', 'WRITE', $arEntityAttr); $this->PrepareEntityAttrs($arEntityAttr, $sEntityPerm); //Prevent 'OPENED' field change by user restricted by BX_CRM_PERM_OPEN permission if ($sEntityPerm === BX_CRM_PERM_OPEN && isset($arFields['OPENED']) && $arFields['OPENED'] !== 'Y' && $assignedByID !== $iUserId) { $arFields['OPENED'] = 'Y'; } if (isset($arFields['ASSIGNED_BY_ID']) && $arRow['ASSIGNED_BY_ID'] != $arFields['ASSIGNED_BY_ID']) { CCrmEvent::SetAssignedByElement($arFields['ASSIGNED_BY_ID'], 'DEAL', $ID); } $sonetEventData = array(); if ($bCompare) { $arEvents = self::CompareFields($arRow, $arFields, $this->bCheckPermission); foreach ($arEvents as $arEvent) { $arEvent['ENTITY_TYPE'] = 'DEAL'; $arEvent['ENTITY_ID'] = $ID; $arEvent['EVENT_TYPE'] = 1; if (!isset($arEvent['USER_ID'])) { $arEvent['USER_ID'] = $iUserId; } $CCrmEvent = new CCrmEvent(); $eventID = $CCrmEvent->Add($arEvent, $this->bCheckPermission); if (is_int($eventID) && $eventID > 0) { $fieldID = isset($arEvent['ENTITY_FIELD']) ? $arEvent['ENTITY_FIELD'] : ''; if ($fieldID === '') { continue; } switch ($fieldID) { case 'STAGE_ID': $sonetEventData[CCrmLiveFeedEvent::Progress] = array('TYPE' => CCrmLiveFeedEvent::Progress, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_STAGE'), 'MESSAGE' => '', 'PARAMS' => array('START_STATUS_ID' => $arRow['STAGE_ID'], 'FINAL_STATUS_ID' => $arFields['STAGE_ID']))); break; case 'ASSIGNED_BY_ID': $sonetEventData[CCrmLiveFeedEvent::Responsible] = array('TYPE' => CCrmLiveFeedEvent::Responsible, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_ASSIGNED_BY'), 'MESSAGE' => '', 'PARAMS' => array('START_RESPONSIBLE_ID' => $arRow['ASSIGNED_BY_ID'], 'FINAL_RESPONSIBLE_ID' => $arFields['ASSIGNED_BY_ID']))); break; case 'CONTACT_ID': case 'COMPANY_ID': if (!isset($sonetEventData[CCrmLiveFeedEvent::Client])) { $oldContactID = isset($arRow['CONTACT_ID']) ? intval($arRow['CONTACT_ID']) : 0; $oldCompanyID = isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0; $sonetEventData[CCrmLiveFeedEvent::Client] = array('CODE' => 'CLIENT', 'TYPE' => CCrmLiveFeedEvent::Client, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_CLIENT'), 'MESSAGE' => '', 'PARAMS' => array('START_CLIENT_CONTACT_ID' => $oldContactID, 'FINAL_CLIENT_CONTACT_ID' => isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : $oldContactID, 'START_CLIENT_COMPANY_ID' => $oldCompanyID, 'FINAL_CLIENT_COMPANY_ID' => isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : $oldCompanyID))); } break; case 'TITLE': $sonetEventData[CCrmLiveFeedEvent::Denomination] = array('TYPE' => CCrmLiveFeedEvent::Denomination, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_TITLE'), 'MESSAGE' => '', 'PARAMS' => array('START_TITLE' => $arRow['TITLE'], 'FINAL_TITLE' => $arFields['TITLE']))); break; } } } // CHECK IF COMPANY/CONTACT WAS ADDED/REMOVED if (!isset($sonetEventData[CCrmLiveFeedEvent::Client]) && (!isset($arRow['COMPANY_ID']) && isset($arFields['COMPANY_ID']) || isset($arRow['COMPANY_ID']) && !isset($arFields['COMPANY_ID']) || !isset($arRow['CONTACT_ID']) && isset($arFields['CONTACT_ID']) || isset($arRow['CONTACT_ID']) && !isset($arFields['CONTACT_ID']))) { $sonetEventData[CCrmLiveFeedEvent::Client] = array('CODE' => 'CLIENT', 'TYPE' => CCrmLiveFeedEvent::Client, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_CLIENT'), 'MESSAGE' => '', 'PARAMS' => array('START_CLIENT_CONTACT_ID' => isset($arRow['CONTACT_ID']) ? intval($arRow['CONTACT_ID']) : 0, 'FINAL_CLIENT_CONTACT_ID' => isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : 0, 'START_CLIENT_COMPANY_ID' => isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0, 'FINAL_CLIENT_COMPANY_ID' => isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0))); } } // Calculation of Account Data $accData = CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => isset($arFields['CURRENCY_ID']) ? $arFields['CURRENCY_ID'] : (isset($arRow['CURRENCY_ID']) ? $arRow['CURRENCY_ID'] : null), 'SUM' => isset($arFields['OPPORTUNITY']) ? $arFields['OPPORTUNITY'] : (isset($arRow['OPPORTUNITY']) ? $arRow['OPPORTUNITY'] : null), 'EXCH_RATE' => isset($arFields['EXCH_RATE']) ? $arFields['EXCH_RATE'] : (isset($arRow['EXCH_RATE']) ? $arRow['EXCH_RATE'] : null))); if (is_array($accData)) { $arFields['ACCOUNT_CURRENCY_ID'] = $accData['ACCOUNT_CURRENCY_ID']; $arFields['OPPORTUNITY_ACCOUNT'] = $accData['ACCOUNT_SUM']; } $accData = CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => isset($arFields['CURRENCY_ID']) ? $arFields['CURRENCY_ID'] : (isset($arRow['CURRENCY_ID']) ? $arRow['CURRENCY_ID'] : null), 'SUM' => isset($arFields['TAX_VALUE']) ? $arFields['TAX_VALUE'] : (isset($arRow['TAX_VALUE']) ? $arRow['TAX_VALUE'] : null), 'EXCH_RATE' => isset($arFields['EXCH_RATE']) ? $arFields['EXCH_RATE'] : (isset($arRow['EXCH_RATE']) ? $arRow['EXCH_RATE'] : null))); if (is_array($accData)) { $arFields['TAX_VALUE_ACCOUNT'] = $accData['ACCOUNT_SUM']; } $enableCloseDateSync = \Bitrix\Crm\Settings\DealSettings::isCloseDateSyncEnabled(); if (isset($arFields['STAGE_ID'])) { $now = ConvertTimeStamp(time(), 'SHORT', SITE_ID); $isFinalStage = self::GetStageSemantics($arFields['STAGE_ID']) !== 'process'; $isStageChanged = !isset($arRow['STAGE_ID']) || $arRow['STAGE_ID'] !== $arFields['STAGE_ID']; $arFields['CLOSED'] = $isFinalStage ? 'Y' : 'N'; if ($enableCloseDateSync && $isFinalStage && $isStageChanged) { $arFields['CLOSEDATE'] = $now; $arFields['~CLOSEDATE'] = $DB->CharToDateFunction($now, 'SHORT', false); } elseif (isset($arFields['CLOSEDATE']) && $arFields['CLOSEDATE'] !== '') { $arFields['~CLOSEDATE'] = $DB->CharToDateFunction($arFields['CLOSEDATE'], 'SHORT', false); } } elseif ($enableCloseDateSync && self::GetStageSemantics($arRow['STAGE_ID']) !== 'process' && isset($arFields['CLOSEDATE'])) { unset($arFields['CLOSEDATE']); } if (isset($arFields['BEGINDATE']) && $arFields['BEGINDATE'] !== '') { $arFields['~BEGINDATE'] = $DB->CharToDateFunction($arFields['BEGINDATE'], 'SHORT', false); } if (isset($arFields['BEGINDATE'])) { $arFields['__BEGINDATE'] = $arFields['BEGINDATE']; unset($arFields['BEGINDATE']); } if (isset($arFields['CLOSEDATE'])) { $arFields['__CLOSEDATE'] = $arFields['CLOSEDATE']; unset($arFields['CLOSEDATE']); } unset($arFields['ID']); $sUpdate = $DB->PrepareUpdate('b_crm_deal', $arFields); if (strlen($sUpdate) > 0) { $DB->Query("UPDATE b_crm_deal SET {$sUpdate} WHERE ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); $bResult = true; } //Restore BEGINDATE and CLOSEDATE if (isset($arFields['__BEGINDATE'])) { $arFields['BEGINDATE'] = $arFields['__BEGINDATE']; unset($arFields['__BEGINDATE']); } if (isset($arFields['__CLOSEDATE'])) { $arFields['CLOSEDATE'] = $arFields['__CLOSEDATE']; unset($arFields['__CLOSEDATE']); } if (defined("BX_COMP_MANAGED_CACHE")) { static $arNameFields = array("TITLE"); $bClear = false; foreach ($arNameFields as $val) { if (isset($arFields[$val])) { $bClear = true; break; } } if ($bClear) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Deal . "_" . $ID); } } CCrmPerms::UpdateEntityAttr('DEAL', $ID, $arEntityAttr); CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => false)); $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $ID, $arFields); //Statistics & History --> $currentDbResult = \CCrmDeal::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*')); $currentFields = $currentDbResult->Fetch(); Bitrix\Crm\Statistics\DealSumStatisticEntry::register($ID, $currentFields); Bitrix\Crm\History\DealStageHistoryEntry::synchronize($ID, $currentFields); Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::synchronize($ID, $currentFields); Bitrix\Crm\Statistics\DealActivityStatisticEntry::synchronize($ID, $currentFields); if (isset($arFields['STAGE_ID'])) { Bitrix\Crm\History\DealStageHistoryEntry::register($ID, $arFields, array('IS_NEW' => false)); } //<-- Statistics & History if ($bUpdateSearch) { $arFilterTmp = array('ID' => $ID); if (!$this->bCheckPermission) { $arFilterTmp['CHECK_PERMISSIONS'] = 'N'; } CCrmSearch::UpdateSearch($arFilterTmp, 'DEAL', true); } $arFields['ID'] = $ID; if (isset($arFields['FM']) && is_array($arFields['FM'])) { $CCrmFieldMulti = new CCrmFieldMulti(); $CCrmFieldMulti->SetFields('DEAL', $ID, $arFields['FM']); } // Responsible user sync //CCrmActivity::Synchronize(CCrmOwnerType::Deal, $ID); $registerSonetEvent = isset($options['REGISTER_SONET_EVENT']) && $options['REGISTER_SONET_EVENT'] === true; if ($bResult && isset($arFields['ASSIGNED_BY_ID'])) { CCrmSonetSubscription::ReplaceSubscriptionByEntity(CCrmOwnerType::Deal, $ID, CCrmSonetSubscriptionType::Responsibility, $arFields['ASSIGNED_BY_ID'], $arRow['ASSIGNED_BY_ID'], $registerSonetEvent); } if ($bResult && $bCompare && $registerSonetEvent && !empty($sonetEventData)) { //CONTACT $newContactID = isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : 0; $oldContactID = isset($arRow['CONTACT_ID']) ? intval($arRow['CONTACT_ID']) : 0; $contactID = $newContactID > 0 ? $newContactID : $oldContactID; //COMPANY $newCompanyID = isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0; $oldCompanyID = isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0; $companyID = $newCompanyID > 0 ? $newCompanyID : $oldCompanyID; $modifiedByID = intval($arFields['MODIFY_BY_ID']); foreach ($sonetEventData as &$sonetEvent) { $sonetEventType = $sonetEvent['TYPE']; $sonetEventCode = isset($sonetEvent['CODE']) ? $sonetEvent['CODE'] : ''; $sonetEventFields =& $sonetEvent['FIELDS']; $sonetEventFields['ENTITY_TYPE_ID'] = CCrmOwnerType::Deal; $sonetEventFields['ENTITY_ID'] = $ID; $sonetEventFields['USER_ID'] = $modifiedByID; //Register contact & company relations if ($sonetEventCode === 'CLIENT') { $sonetEventFields['PARENTS'] = array(); //If contact changed bind events to old and new contacts if ($oldContactID !== $newContactID) { if ($oldContactID > 0) { $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $oldContactID); } if ($newContactID > 0) { $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $newContactID); } } //If company changed bind events to old and new companies if ($oldCompanyID !== $newCompanyID) { if ($oldCompanyID > 0) { $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $oldCompanyID); } if ($newCompanyID > 0) { $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $newCompanyID); } } } elseif ($contactID > 0 || $companyID > 0) { $sonetEventFields['PARENTS'] = array(); if ($contactID > 0) { $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $contactID); } if ($companyID > 0) { $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $companyID); } } $logEventID = CCrmLiveFeed::CreateLogEvent($sonetEventFields, $sonetEventType); if ($logEventID && CModule::IncludeModule("im")) { $url = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Deal, $ID); $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", "")); if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Responsible && $sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'] != $modifiedByID) { $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "deal_update", "NOTIFY_TAG" => "CRM|DEAL_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_DEAL_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_DEAL_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']))) . " (" . $serverName . $url . ")"); CIMNotify::Add($arMessageFields); } if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Responsible && $sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'] != $modifiedByID) { $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "deal_update", "NOTIFY_TAG" => "CRM|DEAL_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_DEAL_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_DEAL_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']))) . " (" . $serverName . $url . ")"); CIMNotify::Add($arMessageFields); } if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Progress && $sonetEventFields['PARAMS']['START_STATUS_ID'] && $sonetEventFields['PARAMS']['FINAL_STATUS_ID']) { $assignedByID = isset($arFields['ASSIGNED_BY_ID']) ? $arFields['ASSIGNED_BY_ID'] : $arRow['ASSIGNED_BY_ID']; $infos = CCrmStatus::GetStatus('DEAL_STAGE'); if ($assignedByID != $modifiedByID && array_key_exists($sonetEventFields['PARAMS']['START_STATUS_ID'], $infos) && array_key_exists($sonetEventFields['PARAMS']['FINAL_STATUS_ID'], $infos)) { $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $assignedByID, "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "deal_update", "NOTIFY_TAG" => "CRM|DEAL_PROGRESS|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_DEAL_PROGRESS_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>", "#start_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['START_STATUS_ID']]['NAME']), "#final_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['FINAL_STATUS_ID']]['NAME']))), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_DEAL_PROGRESS_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']), "#start_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['START_STATUS_ID']]['NAME']), "#final_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['FINAL_STATUS_ID']]['NAME']))) . " (" . $serverName . $url . ")"); CIMNotify::Add($arMessageFields); } } } unset($sonetEventFields); } unset($sonetEvent); } if ($bResult) { $afterEvents = GetModuleEvents('crm', 'OnAfterCrmDealUpdate'); while ($arEvent = $afterEvents->Fetch()) { ExecuteModuleEventEx($arEvent, array(&$arFields)); } } self::PullChange('UPDATE', array('ID' => $ID)); } return $bResult; }
public function Update($ID, &$arFields, $bCompare = true, $bUpdateSearch = true, $options = array()) { global $DB; $this->LAST_ERROR = ''; $ID = (int) $ID; if (!is_array($options)) { $options = array(); } $arFilterTmp = array('ID' => $ID); if (!$this->bCheckPermission) { $arFilterTmp['CHECK_PERMISSIONS'] = 'N'; } $obRes = self::GetList(array(), $arFilterTmp); if (!($arRow = $obRes->Fetch())) { return false; } $iUserId = CCrmSecurityHelper::GetCurrentUserID(); if (isset($arFields['DATE_CREATE'])) { unset($arFields['DATE_CREATE']); } if (isset($arFields['DATE_MODIFY'])) { unset($arFields['DATE_MODIFY']); } $arFields['~DATE_MODIFY'] = $DB->CurrentTimeFunction(); if (!isset($arFields['MODIFY_BY_ID']) || $arFields['MODIFY_BY_ID'] <= 0) { $arFields['MODIFY_BY_ID'] = $iUserId; } if (isset($arFields['ASSIGNED_BY_ID']) && $arFields['ASSIGNED_BY_ID'] <= 0) { unset($arFields['ASSIGNED_BY_ID']); } // number if (!isset($arFields['QUOTE_NUMBER']) || empty($arFields['QUOTE_NUMBER'])) { $arFields['QUOTE_NUMBER'] = isset($arRow['QUOTE_NUMBER']) ? $arRow['QUOTE_NUMBER'] : ''; if (empty($arFields['QUOTE_NUMBER'])) { $arFields['QUOTE_NUMBER'] = strval($ID); } } // person type if (!isset($arFields['PERSON_TYPE_ID']) || intval($arFields['PERSON_TYPE_ID']) <= 0) { $companyId = isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : (isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0); $arFields['PERSON_TYPE_ID'] = intval($arRow['PERSON_TYPE_ID']); $arPersonTypes = CCrmPaySystem::getPersonTypeIDs(); if (isset($arPersonTypes['CONTACT']) && isset($arPersonTypes['COMPANY'])) { if ($companyId <= 0) { $arFields['PERSON_TYPE_ID'] = intval($arPersonTypes['CONTACT']); } else { $arFields['PERSON_TYPE_ID'] = intval($arPersonTypes['COMPANY']); } } unset($companyId, $arPersonTypes); } // storage type id $storageTypeID = isset($arFields['STORAGE_TYPE_ID']) ? intval($arFields['STORAGE_TYPE_ID']) : CCrmQuoteStorageType::Undefined; if ($storageTypeID === CCrmQuoteStorageType::Undefined || !CCrmQuoteStorageType::IsDefined($storageTypeID)) { $storageTypeID = isset($arRow['STORAGE_TYPE_ID']) ? $arRow['STORAGE_TYPE_ID'] : CCrmQuoteStorageType::Undefined; if ($storageTypeID === CCrmQuoteStorageType::Undefined || !CCrmQuoteStorageType::IsDefined($storageTypeID)) { $storageTypeID = CCrmQuote::GetDefaultStorageTypeID(); } } $arFields['STORAGE_TYPE_ID'] = $storageTypeID; // storage elements $storageElementIDs = isset($arFields['STORAGE_ELEMENT_IDS']) && is_array($arFields['STORAGE_ELEMENT_IDS']) ? $arFields['STORAGE_ELEMENT_IDS'] : null; $arFields['STORAGE_ELEMENT_IDS'] = null; if ($storageElementIDs !== null) { $storageElementIDs = self::NormalizeStorageElementIDs($storageElementIDs); $arFields['STORAGE_ELEMENT_IDS'] = serialize($storageElementIDs); } $assignedByID = (int) (isset($arFields['ASSIGNED_BY_ID']) ? $arFields['ASSIGNED_BY_ID'] : $arRow['ASSIGNED_BY_ID']); $bResult = false; if (!$this->CheckFields($arFields, $ID, $options)) { $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR; } else { if ($this->bCheckPermission && !CCrmAuthorizationHelper::CheckUpdatePermission(self::$TYPE_NAME, $ID, $this->cPerms)) { $this->LAST_ERROR = GetMessage('CRM_PERMISSION_DENIED'); $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR; return false; } $arAttr = array(); $arAttr['STATUS_ID'] = !empty($arFields['STATUS_ID']) ? $arFields['STATUS_ID'] : $arRow['STATUS_ID']; $arAttr['OPENED'] = !empty($arFields['OPENED']) ? $arFields['OPENED'] : $arRow['OPENED']; $arEntityAttr = self::BuildEntityAttr($assignedByID, $arAttr); $sEntityPerm = $this->cPerms->GetPermType('QUOTE', 'WRITE', $arEntityAttr); $this->PrepareEntityAttrs($arEntityAttr, $sEntityPerm); //Prevent 'OPENED' field change by user restricted by BX_CRM_PERM_OPEN permission if ($sEntityPerm === BX_CRM_PERM_OPEN && isset($arFields['OPENED']) && $arFields['OPENED'] !== 'Y' && $assignedByID !== $iUserId) { $arFields['OPENED'] = 'Y'; } if (isset($arFields['ASSIGNED_BY_ID']) && $arRow['ASSIGNED_BY_ID'] != $arFields['ASSIGNED_BY_ID']) { CCrmEvent::SetAssignedByElement($arFields['ASSIGNED_BY_ID'], 'QUOTE', $ID); } if ($bCompare) { $arEvents = self::CompareFields($arRow, $arFields, $this->bCheckPermission); foreach ($arEvents as $arEvent) { $arEvent['ENTITY_TYPE'] = 'QUOTE'; $arEvent['ENTITY_ID'] = $ID; $arEvent['EVENT_TYPE'] = 1; if (!isset($arEvent['USER_ID'])) { $arEvent['USER_ID'] = $iUserId; } $CCrmEvent = new CCrmEvent(); $eventID = $CCrmEvent->Add($arEvent, $this->bCheckPermission); } } // Calculation of Account Data $accData = CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => isset($arFields['CURRENCY_ID']) ? $arFields['CURRENCY_ID'] : (isset($arRow['CURRENCY_ID']) ? $arRow['CURRENCY_ID'] : null), 'SUM' => isset($arFields['OPPORTUNITY']) ? $arFields['OPPORTUNITY'] : (isset($arRow['OPPORTUNITY']) ? $arRow['OPPORTUNITY'] : null), 'EXCH_RATE' => isset($arFields['EXCH_RATE']) ? $arFields['EXCH_RATE'] : (isset($arRow['EXCH_RATE']) ? $arRow['EXCH_RATE'] : null))); if (is_array($accData)) { $arFields['ACCOUNT_CURRENCY_ID'] = $accData['ACCOUNT_CURRENCY_ID']; $arFields['OPPORTUNITY_ACCOUNT'] = $accData['ACCOUNT_SUM']; } $accData = CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => isset($arFields['CURRENCY_ID']) ? $arFields['CURRENCY_ID'] : (isset($arRow['CURRENCY_ID']) ? $arRow['CURRENCY_ID'] : null), 'SUM' => isset($arFields['TAX_VALUE']) ? $arFields['TAX_VALUE'] : (isset($arRow['TAX_VALUE']) ? $arRow['TAX_VALUE'] : null), 'EXCH_RATE' => isset($arFields['EXCH_RATE']) ? $arFields['EXCH_RATE'] : (isset($arRow['EXCH_RATE']) ? $arRow['EXCH_RATE'] : null))); if (is_array($accData)) { $arFields['TAX_VALUE_ACCOUNT'] = $accData['ACCOUNT_SUM']; } if (isset($arFields['STATUS_ID'])) { $arFields['CLOSED'] = self::GetStatusSemantics($arFields['STATUS_ID']) === 'process' ? 'N' : 'Y'; } if (isset($arFields['BEGINDATE']) && !isset($arFields['BEGINDATE'][0])) { unset($arFields['BEGINDATE']); } if (isset($arFields['CLOSED']) && $arFields['CLOSED'] === 'Y' && (!isset($arFields['CLOSEDATE']) || $arFields['CLOSEDATE'] === '')) { $arFields['CLOSEDATE'] = ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL', SITE_ID); } if (!isset($arFields['ID'])) { $arFields['ID'] = $ID; } foreach (GetModuleEvents('crm', 'OnBeforeCrmQuoteUpdate', true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) { if (isset($arFields['RESULT_MESSAGE'])) { $this->LAST_ERROR = $arFields['RESULT_MESSAGE']; } else { $this->LAST_ERROR = GetMessage('CRM_QUOTE_UPDATE_CANCELED', array('#NAME#' => $arEvent['TO_NAME'])); $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR; } return false; } } unset($arFields['ID']); $sUpdate = $DB->PrepareUpdate('b_crm_quote', $arFields); if (strlen($sUpdate) > 0) { $clobFieldNames = array('COMMENTS', 'CONTENT', 'STORAGE_ELEMENT_IDS'); $arBinds = array(); foreach ($clobFieldNames as $fieldName) { if (array_key_exists($fieldName, $arFields)) { $arBinds[$fieldName] = $arFields[$fieldName]; } } unset($fieldName); $sql = "UPDATE b_crm_quote SET {$sUpdate} WHERE ID = {$ID}"; if (!empty($arBinds)) { $DB->QueryBind($sql, $arBinds, false); } else { $DB->Query($sql, false, 'File: ' . __FILE__ . '<br>Line: ' . __LINE__); } $bResult = true; } if (defined("BX_COMP_MANAGED_CACHE")) { static $arNameFields = array("TITLE"); $bClear = false; foreach ($arNameFields as $val) { if (isset($arFields[$val])) { $bClear = true; break; } } if ($bClear) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Quote . "_" . $ID); } } CCrmPerms::UpdateEntityAttr('QUOTE', $ID, $arEntityAttr); CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => false)); $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $ID, $arFields); if (is_array($storageElementIDs)) { CCrmQuote::DoSaveElementIDs($ID, $storageTypeID, $storageElementIDs); } unset($storageTypeID, $storageElementIDs); if ($bUpdateSearch) { $arFilterTmp = array('ID' => $ID); if (!$this->bCheckPermission) { $arFilterTmp["CHECK_PERMISSIONS"] = "N"; } CCrmSearch::UpdateSearch($arFilterTmp, 'QUOTE', true); } $arFields['ID'] = $ID; if (isset($arFields['FM']) && is_array($arFields['FM'])) { $CCrmFieldMulti = new CCrmFieldMulti(); $CCrmFieldMulti->SetFields('QUOTE', $ID, $arFields['FM']); } // Responsible user sync //CCrmActivity::Synchronize(CCrmOwnerType::Quote, $ID); if ($bResult) { foreach (GetModuleEvents('crm', 'OnAfterCrmQuoteUpdate', true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arFields)); } } } return $bResult; }
public function CheckFields(&$arFields, $ID = false, $options = array()) { global $APPLICATION, $USER_FIELD_MANAGER; $this->LAST_ERROR = ''; if (($ID == false || isset($arFields['TITLE'])) && empty($arFields['TITLE'])) { $this->LAST_ERROR .= GetMessage('CRM_ERROR_FIELD_IS_MISSING', array('%FIELD_NAME%' => GetMessage('CRM_FIELD_TITLE'))) . "<br />"; } if (is_string($arFields['OPPORTUNITY']) && $arFields['OPPORTUNITY'] !== '') { $arFields['OPPORTUNITY'] = str_replace(array(',', ' '), array('.', ''), $arFields['OPPORTUNITY']); //HACK: MSSQL returns '.00' for zero value if (strpos($arFields['OPPORTUNITY'], '.') === 0) { $arFields['OPPORTUNITY'] = '0' . $arFields['OPPORTUNITY']; } if (!preg_match('/^\\d{1,}(\\.\\d{1,})?$/', $arFields['OPPORTUNITY'])) { $this->LAST_ERROR .= GetMessage('CRM_LEAD_FIELD_OPPORTUNITY_INVALID') . "<br />"; } } if (isset($arFields['FM']) && is_array($arFields['FM'])) { $CCrmFieldMulti = new CCrmFieldMulti(); if (!$CCrmFieldMulti->CheckComplexFields($arFields['FM'])) { $this->LAST_ERROR .= $CCrmFieldMulti->LAST_ERROR; } } if (isset($arFields['BIRTHDATE']) && $arFields['BIRTHDATE'] !== '' && !CheckDateTime($arFields['BIRTHDATE'])) { $this->LAST_ERROR .= GetMessage('CRM_ERROR_FIELD_INCORRECT', array('%FIELD_NAME%' => self::GetFieldCaption('BIRTHDATE'))) . "<br />"; } $enableUserFildCheck = !(is_array($options) && isset($options['DISABLE_USER_FIELD_CHECK']) && $options['DISABLE_USER_FIELD_CHECK'] === true); if ($enableUserFildCheck) { // We have to prepare field data before check (issue #22966) CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $USER_FIELD_MANAGER, array('IS_NEW' => $ID == false)); if (!$USER_FIELD_MANAGER->CheckFields(self::$sUFEntityID, $ID, $arFields)) { $e = $APPLICATION->GetException(); $this->LAST_ERROR .= $e->GetString(); } } return $this->LAST_ERROR === ''; }
public static function GetByID($ID, $bRealPrice = false) { $arResult = CCrmEntityHelper::GetCached(self::CACHE_NAME . ($bRealPrice !== false ? '_RP' : ''), $ID); if (is_array($arResult)) { return $arResult; } $arFilter = array('=ID' => intval($ID)); if ($bRealPrice !== false) { $arFilter['~REAL_PRICE'] = true; } $dbRes = CCrmProduct::GetList(array(), $arFilter, array('*'), array('nTopCount' => 1)); $arResult = $dbRes->GetNext(); if (is_array($arResult)) { CCrmEntityHelper::SetCached(self::CACHE_NAME . ($bRealPrice !== false ? '_RP' : ''), $ID, $arResult); } return $arResult; }
public function CheckFields(&$arFields, $ID = false, $options = array()) { global $APPLICATION, $USER_FIELD_MANAGER; $this->LAST_ERROR = ''; if (($ID == false || isset($arFields['NAME']) && isset($arFields['LAST_NAME'])) && (empty($arFields['NAME']) && empty($arFields['LAST_NAME']))) { $this->LAST_ERROR .= GetMessage('CRM_ERROR_REQUIRED_FIELDS') . "<br />"; } if (isset($arFields['FM']) && is_array($arFields['FM'])) { $CCrmFieldMulti = new CCrmFieldMulti(); if (!$CCrmFieldMulti->CheckComplexFields($arFields['FM'])) { $this->LAST_ERROR .= $CCrmFieldMulti->LAST_ERROR; } } if (isset($arFields['PHOTO']) && is_array($arFields['PHOTO'])) { if (($strError = CFile::CheckFile($arFields['PHOTO'], 0, 0, CFile::GetImageExtensions())) != '') { $this->LAST_ERROR .= $strError . "<br />"; } } if (isset($arFields['BIRTHDATE']) && $arFields['BIRTHDATE'] !== '' && !CheckDateTime($arFields['BIRTHDATE'])) { $this->LAST_ERROR .= GetMessage('CRM_ERROR_FIELD_INCORRECT', array('%FIELD_NAME%' => self::GetFieldCaption('BIRTHDATE'))) . "<br />"; } $enableUserFildCheck = !(is_array($options) && isset($options['DISABLE_USER_FIELD_CHECK']) && $options['DISABLE_USER_FIELD_CHECK'] === true); if ($enableUserFildCheck) { // We have to prepare field data before check (issue #22966) CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $USER_FIELD_MANAGER, array('IS_NEW' => $ID == false)); if (!$USER_FIELD_MANAGER->CheckFields(self::$sUFEntityID, $ID, $arFields)) { $e = $APPLICATION->GetException(); $this->LAST_ERROR .= $e->GetString(); } } return $this->LAST_ERROR === ''; }
public function CheckFields(&$arFields, $ID = false, $options = array()) { global $APPLICATION, $USER_FIELD_MANAGER; $this->LAST_ERROR = ''; if (($ID == false || isset($arFields['TITLE'])) && empty($arFields['TITLE'])) { $this->LAST_ERROR .= GetMessage('CRM_ERROR_FIELD_IS_MISSING', array('%FIELD_NAME%' => GetMessage('CRM_FIELD_TITLE'))) . "<br />"; } if (isset($arFields['FM']) && is_array($arFields['FM'])) { $CCrmFieldMulti = new CCrmFieldMulti(); if (!$CCrmFieldMulti->CheckComplexFields($arFields['FM'])) { $this->LAST_ERROR .= $CCrmFieldMulti->LAST_ERROR; } } if (isset($arFields['LOGO']) && is_array($arFields['LOGO'])) { if (($strError = CFile::CheckFile($arFields['LOGO'], 0, 0, CFile::GetImageExtensions())) != '') { $this->LAST_ERROR .= $strError . "<br />"; } } $enableUserFildCheck = !(is_array($options) && isset($options['DISABLE_USER_FIELD_CHECK']) && $options['DISABLE_USER_FIELD_CHECK'] === true); if ($enableUserFildCheck) { // We have to prepare field data before check (issue #22966) CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $USER_FIELD_MANAGER, array('IS_NEW' => $ID == false)); if (!$USER_FIELD_MANAGER->CheckFields(self::$sUFEntityID, $ID, $arFields)) { $e = $APPLICATION->GetException(); $this->LAST_ERROR .= $e->GetString(); } } if (strlen($this->LAST_ERROR) > 0) { return false; } return true; }
public function Add($arFields, &$arRecalculated = false, $siteId = SITE_ID, $options = array()) { /** @global \CDatabase $DB */ global $DB; if (!CModule::IncludeModule('sale')) { return false; } if (!is_array($options)) { $options = array(); } $bRecalculate = is_array($arRecalculated); $orderID = false; $tmpOrderId = intval($arFields['ID']) <= 0 ? 0 : $arFields['ID']; if (isset($arFields['ID'])) { unset($arFields['ID']); } $arPrevOrder = $tmpOrderId !== 0 ? CCrmInvoice::GetByID($tmpOrderId) : null; $userId = CCrmSecurityHelper::GetCurrentUserID(); if (!isset($arFields['RESPONSIBLE_ID']) || (int) $arFields['RESPONSIBLE_ID'] <= 0) { if (is_array($arPrevOrder) && isset($arPrevOrder['RESPONSIBLE_ID']) && intval($arPrevOrder['RESPONSIBLE_ID']) > 0) { $arFields['RESPONSIBLE_ID'] = $arPrevOrder['RESPONSIBLE_ID']; } else { $arFields['RESPONSIBLE_ID'] = $userId; } } $orderStatus = ''; if (isset($arFields['STATUS_ID'])) { $orderStatus = $arFields['STATUS_ID']; unset($arFields['STATUS_ID']); } // prepare entity permissions $arAttr = array(); if (!empty($arFields['OPENED'])) { $arAttr['OPENED'] = $arFields['OPENED']; } $sPermission = $tmpOrderId > 0 ? 'WRITE' : 'ADD'; if ($this->bCheckPermission) { $arEntityAttr = self::BuildEntityAttr($userId, $arAttr); $userPerms = $userId == CCrmPerms::GetCurrentUserID() ? $this->cPerms : CCrmPerms::GetUserPermissions($userId); $sEntityPerm = $userPerms->GetPermType('INVOICE', $sPermission, $arEntityAttr); if ($sEntityPerm == BX_CRM_PERM_NONE) { $this->LAST_ERROR = GetMessage('CRM_PERMISSION_DENIED'); $GLOBALS['APPLICATION']->ThrowException($this->LAST_ERROR); return false; } $responsibleID = intval($arFields['RESPONSIBLE_ID']); if ($sEntityPerm == BX_CRM_PERM_SELF && $responsibleID != $userId) { $arFields['RESPONSIBLE_ID'] = $userId; } if ($sEntityPerm == BX_CRM_PERM_OPEN && $userId == $responsibleID) { $arFields['OPENED'] = 'Y'; } } $responsibleID = intval($arFields['RESPONSIBLE_ID']); $arEntityAttr = self::BuildEntityAttr($responsibleID, $arAttr); $userPerms = $responsibleID == CCrmPerms::GetCurrentUserID() ? $this->cPerms : CCrmPerms::GetUserPermissions($responsibleID); $sEntityPerm = $userPerms->GetPermType('INVOICE', $sPermission, $arEntityAttr); $this->PrepareEntityAttrs($arEntityAttr, $sEntityPerm); // date fields if ($tmpOrderId === 0) { $arFields['~DATE_BILL'] = $DB->CharToDateFunction(isset($arFields['DATE_BILL']) && $arFields['DATE_BILL'] !== '' ? $arFields['DATE_BILL'] : ConvertTimeStamp(time(), 'SHORT', SITE_ID), 'SHORT', false); } else { if (isset($arFields['DATE_BILL']) && $arFields['DATE_BILL'] !== '') { $arFields['~DATE_BILL'] = $DB->CharToDateFunction($arFields['DATE_BILL'], 'SHORT', false); } } unset($arFields['DATE_BILL']); if (isset($arFields['DATE_PAY_BEFORE']) && $arFields['DATE_PAY_BEFORE'] !== '') { $arFields['~DATE_PAY_BEFORE'] = $DB->CharToDateFunction($arFields['DATE_PAY_BEFORE'], 'SHORT', false); } unset($arFields['DATE_PAY_BEFORE']); if ($tmpOrderId !== 0 && !isset($arFields['PRODUCT_ROWS']) && !isset($arFields['INVOICE_PROPERTIES'])) { if (!is_array($arPrevOrder)) { return false; } $prevResponsibleID = isset($arPrevOrder['RESPONSIBLE_ID']) ? intval($arPrevOrder['RESPONSIBLE_ID']) : 0; $responsibleID = isset($arFields['RESPONSIBLE_ID']) ? intval($arFields['RESPONSIBLE_ID']) : 0; $prevStatusID = isset($arPrevOrder['STATUS_ID']) ? $arPrevOrder['STATUS_ID'] : ''; // simple update order fields $CSaleOrder = new CSaleOrder(); $orderID = $CSaleOrder->Update($tmpOrderId, $arFields); CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => false)); $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $tmpOrderId, $arFields); $registerSonetEvent = isset($options['REGISTER_SONET_EVENT']) && $options['REGISTER_SONET_EVENT'] === true; if (is_int($orderID) && $orderID > 0) { if ($registerSonetEvent) { $newDealID = isset($arFields['UF_DEAL_ID']) ? intval($arFields['UF_DEAL_ID']) : 0; $oldDealID = isset($arPrevOrder['UF_DEAL_ID']) ? intval($arPrevOrder['UF_DEAL_ID']) : 0; $newCompanyID = isset($arFields['UF_COMPANY_ID']) ? intval($arFields['UF_COMPANY_ID']) : 0; $oldCompanyID = isset($arPrevOrder['UF_COMPANY_ID']) ? intval($arPrevOrder['UF_COMPANY_ID']) : 0; $newContactID = isset($arFields['UF_CONTACT_ID']) ? intval($arFields['UF_CONTACT_ID']) : 0; $oldContactID = isset($arPrevOrder['UF_CONTACT_ID']) ? intval($arPrevOrder['UF_CONTACT_ID']) : 0; $parents = array(); $parentsChanged = $newDealID !== $oldDealID || $newCompanyID !== $oldCompanyID || $newContactID !== $oldContactID; if ($parentsChanged) { if ($newDealID > 0) { $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Deal, 'ENTITY_ID' => $newDealID); } if ($newCompanyID > 0) { $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $newCompanyID); } if ($newContactID > 0) { $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $newContactID); } } $oldOrderStatus = isset($arPrevOrder['STATUS_ID']) ? $arPrevOrder['STATUS_ID'] : ''; self::SynchronizeLiveFeedEvent($orderID, array('PROCESS_PARENTS' => $parentsChanged, 'PARENTS' => $parents, 'REFRESH_DATE' => $orderStatus !== $oldOrderStatus, 'START_RESPONSIBLE_ID' => $prevResponsibleID, 'FINAL_RESPONSIBLE_ID' => $responsibleID, 'TOPIC' => isset($arPrevOrder['ORDER_TOPIC']) ? $arPrevOrder['ORDER_TOPIC'] : $orderID)); } if ($responsibleID !== $prevResponsibleID) { CCrmSonetSubscription::ReplaceSubscriptionByEntity(CCrmOwnerType::Invoice, $orderID, CCrmSonetSubscriptionType::Responsibility, $responsibleID, $prevResponsibleID, $registerSonetEvent); } } } else { // check product rows if (!isset($arFields['PRODUCT_ROWS']) || !is_array($arFields['PRODUCT_ROWS']) || count($arFields['PRODUCT_ROWS']) <= 0) { return false; } $arProduct = $arFields['PRODUCT_ROWS']; // prepare shopping cart data // <editor-fold defaultstate="collapsed" desc="prepare shopping cart data ..."> // get xml_id fields $catalogXmlId = CCrmCatalog::GetDefaultCatalogXmlId(); $arNewProducts = array(); $bGetBasketXmlIds = false; foreach ($arProduct as &$productRow) { if (isset($productRow['ID']) && intval($productRow['ID']) === 0 && isset($productRow['PRODUCT_ID'])) { $arNewProducts[] = $productRow['PRODUCT_ID']; } else { $bGetBasketXmlIds = true; } } unset($productRow); $arXmlIds = array(); $oldProductRows = null; if ($bGetBasketXmlIds && intval($tmpOrderId) > 0) { $oldProductRows = CCrmInvoice::GetProductRows($tmpOrderId); if (count($oldProductRows) > 0) { foreach ($oldProductRows as $row) { $arXmlIds[intval($row['ID'])][$row['PRODUCT_ID']] = array('CATALOG_XML_ID' => $row['CATALOG_XML_ID'], 'PRODUCT_XML_ID' => $row['PRODUCT_XML_ID']); } unset($row); } } unset($bGetBasketXmlIds); if (count($arNewProducts) > 0) { $dbRes = CCrmProduct::GetList(array(), array('ID' => $arNewProducts), array('ID', 'XML_ID')); while ($row = $dbRes->Fetch()) { $arXmlIds[0][$row['ID']] = array('CATALOG_XML_ID' => $catalogXmlId, 'PRODUCT_XML_ID' => $row['XML_ID']); } unset($dbRes, $row); } unset($arNewProducts, $arOldProducts); // products without measures $productMeasures = array(); $productId = 0; $productIds = array(); foreach ($arProduct as $productRow) { $productId = intval($productRow['PRODUCT_ID']); if ($productId > 0 && (!array_key_exists('MEASURE_CODE', $productRow) || intval($productRow['MEASURE_CODE']) <= 0)) { $productIds[] = $productId; } } unset($productId, $productRow); if (count($productIds) > 0) { $productMeasures = \Bitrix\Crm\Measure::getProductMeasures($productIds); } unset($productIds); $currencyId = CCrmInvoice::GetCurrencyID($siteId); $i = 0; $defaultMeasure = null; $oldProductRowsById = null; foreach ($arProduct as &$productRow) { $productXmlId = $catalogXmlId = null; $rowIndex = intval($productRow['ID']); $productId = $productRow['PRODUCT_ID']; $isCustomized = isset($productRow['CUSTOMIZED']) && $productRow['CUSTOMIZED'] === 'Y'; $productRow['MODULE'] = $productRow['PRODUCT_PROVIDER_CLASS'] = ''; if ($productId > 0) { if (!$isCustomized) { $productRow['MODULE'] = 'catalog'; $productRow['PRODUCT_PROVIDER_CLASS'] = 'CCatalogProductProvider'; } if (is_array($arXmlIds[$rowIndex]) && isset($arXmlIds[$rowIndex][$productId])) { $catalogXmlId = $arXmlIds[$rowIndex][$productId]['CATALOG_XML_ID']; $productXmlId = $arXmlIds[$rowIndex][$productId]['PRODUCT_XML_ID']; } $productRow['CATALOG_XML_ID'] = $catalogXmlId; $productRow['PRODUCT_XML_ID'] = $productXmlId; } else { $productRow["PRODUCT_XML_ID"] = "CRM-" . randString(8); $ri = new \Bitrix\Main\Type\RandomSequence($productRow["PRODUCT_XML_ID"]); $productRow["PRODUCT_ID"] = $ri->rand(1000000, 9999999); $productRow['CATALOG_XML_ID'] = ''; } if ($isCustomized) { $productRow['CUSTOM_PRICE'] = 'Y'; } if (isset($productRow['PRODUCT_NAME'])) { $productRow['NAME'] = $productRow['PRODUCT_NAME']; unset($productRow['PRODUCT_NAME']); } if (isset($productRow['PRICE'])) { $productRow['PRICE_DEFAULT'] = $productRow['PRICE']; } if (!isset($productRow['CURRENCY'])) { $productRow['CURRENCY'] = $currencyId; } // measures $bRefreshMeasureName = false; if (!array_key_exists('MEASURE_CODE', $productRow) || intval($productRow['MEASURE_CODE'] <= 0)) { if ($oldProductRows === null && $tmpOrderId > 0) { $oldProductRows = CCrmInvoice::GetProductRows($tmpOrderId); } if (is_array($oldProductRows) && count($oldProductRows) > 0 && $oldProductRowsById === null) { $oldProductRowsById = array(); foreach ($oldProductRows as $row) { $oldProductRowsById[intval($row['ID'])] = $row; } unset($row); } if (is_array($oldProductRowsById) && isset($oldProductRowsById[$rowIndex])) { $row = $oldProductRowsById[$rowIndex]; if (intval($productId) === intval($row['PRODUCT_ID'])) { if (isset($row['MEASURE_CODE'])) { $productRow['MEASURE_CODE'] = $row['MEASURE_CODE']; } if (isset($row['MEASURE_NAME'])) { $productRow['MEASURE_NAME'] = $row['MEASURE_NAME']; } else { $bRefreshMeasureName = true; } unset($row); } } } if (!isset($productRow['MEASURE_CODE']) || intval($productRow['MEASURE_CODE']) <= 0) { if ($productId > 0 && isset($productMeasures[$productId])) { $measure = is_array($productMeasures[$productId][0]) ? $productMeasures[$productId][0] : null; if (is_array($measure)) { if (isset($measure['CODE'])) { $productRow['MEASURE_CODE'] = $measure['CODE']; } if (isset($measure['SYMBOL'])) { $productRow['MEASURE_NAME'] = $measure['SYMBOL']; } } unset($measure); } } if (!isset($productRow['MEASURE_CODE']) || intval($productRow['MEASURE_CODE']) <= 0) { if ($defaultMeasure === null) { $defaultMeasure = \Bitrix\Crm\Measure::getDefaultMeasure(); } if (is_array($defaultMeasure)) { $productRow['MEASURE_CODE'] = $defaultMeasure['CODE']; $productRow['MEASURE_NAME'] = $defaultMeasure['SYMBOL']; } } if (isset($productRow['MEASURE_CODE']) && intval($productRow['MEASURE_CODE']) > 0 && ($bRefreshMeasureName || !array_key_exists('MEASURE_NAME', $productRow) || empty($productRow['MEASURE_NAME']))) { $measure = \Bitrix\Crm\Measure::getMeasureByCode($productRow['MEASURE_CODE']); if (is_array($measure) && isset($measure['SYMBOL'])) { $productRow['MEASURE_NAME'] = $measure['SYMBOL']; } unset($measure); } $i++; } unset($productRow, $productMeasures, $catalogXmlId, $productXmlId); $arOrderProductPrice = self::__fGetUserShoppingCart($arProduct, $siteId, 'N'); foreach ($arOrderProductPrice as &$arItem) { $arItem["ID_TMP"] = $arItem["ID"]; $arItem["NAME_TMP"] = $arItem["NAME"]; unset($arItem["ID"]); } unset($arItem); // user id for order $saleUserId = intval(CSaleUser::GetAnonymousUserID()); if ($saleUserId <= 0) { return false; } $arErrors = array(); $arShoppingCart = CSaleBasket::DoGetUserShoppingCart($siteId, $saleUserId, $arOrderProductPrice, $arErrors, array(), $tmpOrderId); if (!is_array($arShoppingCart) || count($arShoppingCart) === 0) { $GLOBALS['APPLICATION']->ThrowException(GetMessage('CRM_ERROR_EMPTY_INVOICE_SPEC')); return false; } foreach ($arShoppingCart as $key => &$arItem) { $arItem["ID"] = $arItem["ID_TMP"]; $arItem["NAME"] = $arItem["NAME_TMP"]; unset($arItem["NAME_TMP"], $arItem["ID_TMP"]); //$arShoppingCart[$key]["ID"] = $arItem["ID"]; } unset($key, $arItem); // </editor-fold> // person type $personTypeId = 0; if (!isset($arFields['PERSON_TYPE_ID']) || intval($arFields['PERSON_TYPE_ID']) <= 0) { $arPersonTypes = CCrmPaySystem::getPersonTypeIDs(); if (isset($arPersonTypes['CONTACT'])) { $personTypeId = intval($arPersonTypes['CONTACT']); } } else { $personTypeId = $arFields['PERSON_TYPE_ID']; } if ($personTypeId <= 0) { return false; } // preparing order to save // <editor-fold defaultstate="collapsed" desc="preparing order to save ..."> $arOrderPropsValues = array(); if (isset($arFields['INVOICE_PROPERTIES']) && is_array($arFields['INVOICE_PROPERTIES']) && count($arFields['INVOICE_PROPERTIES']) > 0) { $arOrderPropsValues = $arFields['INVOICE_PROPERTIES']; } if (isset($arFields['INVOICE_PROPERTIES'])) { unset($arFields['INVOICE_PROPERTIES']); } if (count($arOrderPropsValues) <= 0) { return false; } $deliveryId = null; $paySystemId = $arFields['PAY_SYSTEM_ID']; $arOptions = array('LOCATION_IN_CODES' => true); // let DoCalculateOrder know we send location in CODEs $arErrors = $arWarnings = array(); $CSaleOrder = new CSaleOrder(); $arOrder = $CSaleOrder->DoCalculateOrder($siteId, $saleUserId, $arShoppingCart, $personTypeId, $arOrderPropsValues, $deliveryId, $paySystemId, $arOptions, $arErrors, $arWarnings); if (count($arOrder) <= 0) { return false; } // </editor-fold> if ($bRecalculate) { foreach ($arOrder as $k => $v) { $arRecalculated[$k] = $v; } return true; } // merge order fields $arAdditionalFields = array(); foreach ($arFields as $k => $v) { if ($k === 'PRODUCT_ROWS') { continue; } $arAdditionalFields[$k] = $v; } $arOrder['LOCATION_IN_CODES'] = true; // let DoSaveOrder know we send location in IDs // saving order $arErrors = array(); $orderID = $CSaleOrder->DoSaveOrder($arOrder, $arAdditionalFields, $tmpOrderId, $arErrors); if (is_int($orderID) && $orderID > 0) { CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => $tmpOrderId === 0)); $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $orderID, $arFields); } if (is_int($orderID) && $orderID > 0 && isset($options['REGISTER_SONET_EVENT']) && $options['REGISTER_SONET_EVENT'] === true) { $prevResponsibleID = is_array($arPrevOrder) && isset($arPrevOrder['RESPONSIBLE_ID']) ? intval($arPrevOrder['RESPONSIBLE_ID']) : 0; $responsibleID = isset($arFields['RESPONSIBLE_ID']) ? intval($arFields['RESPONSIBLE_ID']) : 0; if ($tmpOrderId <= 0) { self::RegisterLiveFeedEvent($arFields, $orderID, $userId); if ($responsibleID > 0) { CCrmSonetSubscription::RegisterSubscription(CCrmOwnerType::Invoice, $orderID, CCrmSonetSubscriptionType::Responsibility, $responsibleID); } } else { $newDealID = isset($arFields['UF_DEAL_ID']) ? intval($arFields['UF_DEAL_ID']) : 0; $oldDealID = isset($arPrevOrder['UF_DEAL_ID']) ? intval($arPrevOrder['UF_DEAL_ID']) : 0; $newCompanyID = isset($arFields['UF_COMPANY_ID']) ? intval($arFields['UF_COMPANY_ID']) : 0; $oldCompanyID = isset($arPrevOrder['UF_COMPANY_ID']) ? intval($arPrevOrder['UF_COMPANY_ID']) : 0; $newContactID = isset($arFields['UF_CONTACT_ID']) ? intval($arFields['UF_CONTACT_ID']) : 0; $oldContactID = isset($arPrevOrder['UF_CONTACT_ID']) ? intval($arPrevOrder['UF_CONTACT_ID']) : 0; $parents = array(); $parentsChanged = $newDealID !== $oldDealID || $newCompanyID !== $oldCompanyID || $newContactID !== $oldContactID; if ($parentsChanged) { if ($newDealID > 0) { $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Deal, 'ENTITY_ID' => $newDealID); } if ($newCompanyID > 0) { $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $newCompanyID); } if ($newContactID > 0) { $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $newContactID); } } $oldOrderStatus = isset($arPrevOrder['STATUS_ID']) ? $arPrevOrder['STATUS_ID'] : ''; self::SynchronizeLiveFeedEvent($orderID, array('PROCESS_PARENTS' => $parentsChanged, 'PARENTS' => $parents, 'REFRESH_DATE' => $orderStatus !== $oldOrderStatus, 'START_RESPONSIBLE_ID' => $prevResponsibleID, 'FINAL_RESPONSIBLE_ID' => $responsibleID, 'TOPIC' => isset($arPrevOrder['ORDER_TOPIC']) ? $arPrevOrder['ORDER_TOPIC'] : $orderID)); if ($responsibleID !== $prevResponsibleID) { CCrmSonetSubscription::ReplaceSubscriptionByEntity(CCrmOwnerType::Invoice, $orderID, CCrmSonetSubscriptionType::Responsibility, $responsibleID, $prevResponsibleID, true); } } } } if (intval($orderID) > 0 && !empty($orderStatus)) { // set status $this->SetStatus($orderID, $orderStatus); // update entity permissions CCrmPerms::UpdateEntityAttr('INVOICE', $orderID, $arEntityAttr); $newDealID = isset($arFields['UF_DEAL_ID']) ? (int) $arFields['UF_DEAL_ID'] : 0; $oldDealID = is_array($arPrevOrder) && isset($arPrevOrder['UF_DEAL_ID']) ? (int) $arPrevOrder['UF_DEAL_ID'] : 0; if ($newDealID) { Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::register($newDealID); } if ($oldDealID > 0 && $oldDealID !== $newDealID) { Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::register($oldDealID); } if (isset($options['UPDATE_SEARCH']) && $options['UPDATE_SEARCH'] === true) { $arFilterTmp = array('ID' => $orderID); if (!$this->bCheckPermission) { $arFilterTmp["CHECK_PERMISSIONS"] = "N"; } CCrmSearch::UpdateSearch($arFilterTmp, 'INVOICE', true); } } return $orderID; }
public static function GetByID($ID) { $arResult = CCrmEntityHelper::GetCached(self::CACHE_NAME, $ID); if (is_array($arResult)) { return $arResult; } $dbRes = CCrmCatalog::GetList(array(), array('ID' => intval($ID))); $arResult = $dbRes->Fetch(); if (is_array($arResult)) { CCrmEntityHelper::SetCached(self::CACHE_NAME, $ID, $arResult); } return $arResult; }
public static function GetByID($ID) { $ID = intval($ID); $arResult = CCrmEntityHelper::GetCached(self::CACHE_NAME, $ID); if (is_array($arResult)) { return $arResult; } $dbRes = CCrmProductRow::GetList(array(), array('ID' => $ID)); $arResult = $dbRes->Fetch(); if (is_array($arResult)) { CCrmEntityHelper::SetCached(self::CACHE_NAME, $ID, $arResult); if (isset($arResult['OWNER_TYPE'])) { // Remove space padding of CHAR column $arResult['OWNER_TYPE'] = trim($arResult['OWNER_TYPE']); } $productID = $arResult['PRODUCT_ID'] = intval($arResult['PRODUCT_ID']); $arResult['PRICE'] = round(doubleval($arResult['PRICE']), 2); $arResult['QUANTITY'] = round(doubleval($arResult['QUANTITY']), 4); $arResult['DISCOUNT_TYPE_ID'] = isset($arResult['DISCOUNT_TYPE_ID']) ? intval($arResult['DISCOUNT_TYPE_ID']) : \Bitrix\Crm\Discount::UNDEFINED; $arResult['DISCOUNT_RATE'] = isset($arResult['DISCOUNT_RATE']) ? round(doubleval($arResult['DISCOUNT_RATE']), 2) : 0.0; $arResult['DISCOUNT_SUM'] = isset($arResult['DISCOUNT_SUM']) ? round(doubleval($arResult['DISCOUNT_SUM']), 2) : 0.0; $arResult['TAX_RATE'] = isset($arResult['TAX_RATE']) ? round(doubleval($arResult['TAX_RATE']), 2) : 0.0; $arResult['TAX_INCLUDED'] = isset($arResult['TAX_INCLUDED']) ? $arResult['DISCOUNT_SUM'] : 'N'; $arResult['CUSTOMIZED'] = isset($arResult['CUSTOMIZED']) ? $arResult['CUSTOMIZED'] : 'N'; $arResult['MEASURE_CODE'] = isset($arResult['MEASURE_CODE']) ? intval($arResult['MEASURE_CODE']) : 0; $arResult['MEASURE_NAME'] = isset($arResult['MEASURE_NAME']) ? $arResult['MEASURE_NAME'] : ''; if ($productID > 0 && $arResult['MEASURE_CODE'] <= 0) { $defaultMeasureInfo = \Bitrix\Crm\Measure::getDefaultMeasure(); $measureInfos = \Bitrix\Crm\Measure::getProductMeasures($productID); if (isset($measureInfos[$productID]) && !empty($measureInfos[$productID])) { $measureInfo = $measureInfos[$productID][0]; $result['MEASURE_CODE'] = $measureInfo['CODE']; $result['MEASURE_NAME'] = $measureInfo['SYMBOL']; } elseif ($defaultMeasureInfo !== null) { $result['MEASURE_CODE'] = $defaultMeasureInfo['CODE']; $result['MEASURE_NAME'] = $defaultMeasureInfo['SYMBOL']; } } } return $arResult; }
protected function internalizeFilterFields(&$filter, &$fieldsInfo) { if (!is_array($filter)) { return; } foreach ($filter as $k => $v) { $operationInfo = CSqlUtil::GetFilterOperation($k); $fieldName = $operationInfo['FIELD']; $info = isset($fieldsInfo[$fieldName]) ? $fieldsInfo[$fieldName] : null; if (!$info) { unset($filter[$k]); continue; } $fieldType = isset($info['TYPE']) ? $info['TYPE'] : ''; if ($fieldType === 'datetime') { $filter[$k] = CRestUtil::unConvertDateTime($v); } } CCrmEntityHelper::PrepareMultiFieldFilter($filter); }
public static function GetPropertiesDialog($documentType, $activityName, $arWorkflowTemplate, $arWorkflowParameters, $arWorkflowVariables, $arCurrentValues = null, $formName = "") { $runtime = CBPRuntime::GetRuntime(); $arMap = array("MailUserFrom" => "mail_user_from", "MailCrmEntityToArray" => "mail_crm_entity_to", "MailCrmEntityAddressType" => "mail_crm_entity_address_type", "MailSubject" => "mail_subject", "MailText" => "mail_text", "MailMessageType" => "mail_message_type", "MailCharset" => "mail_charset", "DirrectMail" => "dirrect_mail", "MailSite" => "mail_site"); if (!is_array($arWorkflowParameters)) { $arWorkflowParameters = array(); } if (!is_array($arWorkflowVariables)) { $arWorkflowVariables = array(); } if (!is_array($arCurrentValues)) { $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName); if (is_array($arCurrentActivity["Properties"])) { foreach ($arMap as $k => $v) { if (array_key_exists($k, $arCurrentActivity["Properties"])) { if ($k == "MailUserFrom") { $arCurrentValues[$arMap[$k]] = CBPHelper::UsersArrayToString($arCurrentActivity["Properties"][$k . "Array"], $arWorkflowTemplate, $documentType); if (strlen($arCurrentValues[$arMap[$k]]) > 0 && strlen($arCurrentActivity["Properties"][$k]) > 0) { $arCurrentValues[$arMap[$k]] .= ", "; } if (strlen($arCurrentActivity["Properties"][$k]) > 0) { $arCurrentValues[$arMap[$k]] .= $arCurrentActivity["Properties"][$k]; } } else { $arCurrentValues[$arMap[$k]] = $arCurrentActivity["Properties"][$k]; } } else { $arCurrentValues[$arMap[$k]] = ""; } } } else { foreach ($arMap as $k => $v) { $arCurrentValues[$arMap[$k]] = ""; } } } if ($arCurrentValues['dirrect_mail'] != "Y" && $arCurrentValues['dirrect_mail'] != "N") { $arCurrentValues['dirrect_mail'] = "Y"; } global $USER_FIELD_MANAGER; $arUserFieldType = $USER_FIELD_MANAGER->GetUserType('crm'); $mailCrmEntityTo = is_array($arCurrentValues) && isset($arCurrentValues['mail_crm_entity_to']) && is_array($arCurrentValues['mail_crm_entity_to']) ? $arCurrentValues['mail_crm_entity_to'] : array(); $arCurrentValues['mail_crm_entity_to_text'] = ''; $entityKeyCount = count($mailCrmEntityTo); if ($entityKeyCount > 0 && !CCrmEntityHelper::IsEntityKey($mailCrmEntityTo[$entityKeyCount - 1])) { $arCurrentValues['mail_crm_entity_to_text'] = array_pop($mailCrmEntityTo); } return $runtime->ExecuteResourceFile(__FILE__, "properties_dialog.php", array("arCurrentValues" => $arCurrentValues, "formName" => $formName, 'crmEntityToUserField' => array('ENTITY_ID' => 'CRM_' . $documentType[2], 'FIELD_NAME' => 'mail_crm_entity_to', 'USER_TYPE_ID' => 'crm', 'SORT' => 100, 'MULTIPLE' => 'Y', 'MANDATORY' => 'Y', 'EDIT_IN_LIST' => 'Y', 'EDIT_FORM_LABEL' => $arUserFieldType['DESCRIPTION'], 'VALUE' => $mailCrmEntityTo, 'USER_TYPE' => $arUserFieldType, 'SETTINGS' => array('LEAD' => 'Y', 'CONTACT' => 'Y', 'COMPANY' => 'Y', 'DEAL' => 'N')), 'crmEntityAddressTypes' => CCrmFieldMulti::GetEntityTypeList('EMAIL', false))); }
public static function GetByID($ID) { $ID = intval($ID); if ($ID <= 0) { return null; } $res = CCrmEntityHelper::GetCached(self::CACHE_NAME, $ID); if (is_array($res)) { return $res; } $dbRes = self::GetList(array(), array('ID' => $ID)); if (is_array($res = $dbRes->Fetch())) { CCrmEntityHelper::SetCached(self::CACHE_NAME, $ID, $res); } return $res; }
protected function internalizeFilterFields(&$filter, &$fieldsInfo) { if (!is_array($filter)) { return; } foreach ($filter as $k => $v) { $operationInfo = CSqlUtil::GetFilterOperation($k); $fieldName = $operationInfo['FIELD']; $info = isset($fieldsInfo[$fieldName]) ? $fieldsInfo[$fieldName] : null; if (!$info) { unset($filter[$k]); continue; } $operation = substr($k, 0, strlen($k) - strlen($fieldName)); if (isset($info['FORBIDDEN_FILTERS']) && is_array($info['FORBIDDEN_FILTERS']) && in_array($operation, $info['FORBIDDEN_FILTERS'], true)) { unset($filter[$k]); continue; } $fieldType = isset($info['TYPE']) ? $info['TYPE'] : ''; if (($fieldType === 'crm_status' || $fieldType === 'crm_company' || $fieldType === 'crm_contact') && ($operation === '%' || $operation === '%=' || $operation === '=%')) { //Prevent filtration by LIKE due to performance considerations $filter["={$fieldName}"] = $v; unset($filter[$k]); continue; } if ($fieldType === 'datetime') { $filter[$k] = CRestUtil::unConvertDateTime($v); } elseif ($fieldType === 'date') { $filter[$k] = CRestUtil::unConvertDate($v); } } CCrmEntityHelper::PrepareMultiFieldFilter($filter, array(), '=%', true); }