$dealID = intval($_POST['DEAL_ID']); if ($dealID > 0 && CCrmDeal::CheckReadPermission($dealID)) { $arFields['DEAL_ID'] = $dealID; } } elseif (isset($arSrcElement['DEAL_ID'])) { $arFields['DEAL_ID'] = $arSrcElement['DEAL_ID']; } // storage type $storageTypeId = isset($_POST['storageTypeId']) ? intval($_POST['storageTypeId']) : CCrmQuoteStorageType::Undefined; if ($storageTypeId === CCrmQuoteStorageType::Undefined || !CCrmQuoteStorageType::IsDefined($storageTypeId)) { if (!$bEdit) { $storageTypeId = CCrmQuote::GetDefaultStorageTypeID(); } else { $storageTypeId = isset($arSrcElement['STORAGE_TYPE_ID']) ? (int) $arSrcElement['STORAGE_TYPE_ID'] : CCrmQuoteStorageType::Undefined; if ($storageTypeId === CCrmQuoteStorageType::Undefined || !CCrmQuoteStorageType::IsDefined($storageTypeId)) { $storageTypeId = CCrmQuote::GetDefaultStorageTypeID(); } } } $arFields['STORAGE_TYPE_ID'] = $arFields['~STORAGE_TYPE_ID'] = $storageTypeId; // files $arPermittedElements = array(); if ($storageTypeId === CCrmQuoteStorageType::File) { $arPermittedFiles = array(); $arUserFiles = isset($_POST['files']) && is_array($_POST['files']) ? $_POST['files'] : array(); if (!empty($arUserFiles) || $bEdit) { $arPreviousFiles = array(); if ($bEdit) { CCrmQuote::PrepareStorageElementIDs($arSrcElement); $arPreviousFiles = $arSrcElement['STORAGE_ELEMENT_IDS']; if (is_array($arPreviousFiles) && !empty($arPreviousFiles)) {
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; }
} if ($field['id'] === 'PRODUCT_ROWS') { $productFieldset['HTML'] = $field['value']; unset($arTabs[0]['fields'][$k]); break; } } unset($field); $formCustomHtml = '<input type="hidden" name="quote_id" value="' . $elementID . '"/>' . $arResult['FORM_CUSTOM_HTML']; $APPLICATION->IncludeComponent('bitrix:crm.interface.form', 'edit', array('FORM_ID' => $arResult['FORM_ID'], 'GRID_ID' => $arResult['GRID_ID'], 'TABS' => $arTabs, 'FIELD_SETS' => array($productFieldset), 'USER_FIELD_ENTITY_ID' => CCrmQuote::$sUFEntityID, 'BUTTONS' => array('standard_buttons' => true, 'back_url' => $arResult['BACK_URL'], 'custom_html' => $formCustomHtml), 'IS_NEW' => $elementID <= 0, 'TITLE' => $arResult['CRM_CUSTOM_PAGE_TITLE'], 'ENABLE_TACTILE_INTERFACE' => 'Y', 'DATA' => $arResult['ELEMENT'], 'SHOW_SETTINGS' => 'Y')); $prefixLower = strtolower($arResult['PREFIX']); $companySpecifiedClientFields = array('CLIENT_CONTACT', 'CLIENT_TP_ID'); if (LANGUAGE_ID === 'ru') { $companySpecifiedClientFields[] = 'CLIENT_TPA_ID'; } $editorSettings = array('formId' => $arResult['FORM_ID'], 'productRowEditorId' => $arResult['PRODUCT_ROW_EDITOR_ID'], 'url' => '/bitrix/components/bitrix/crm.quote.edit/ajax.php?' . bitrix_sessid_get(), 'personType' => $arResult['PERSON_TYPE'], 'contactId' => intval($arResult['ELEMENT']['CONTACT_ID']), 'companyId' => intval($arResult['ELEMENT']['COMPANY_ID']), 'personTypeIds' => $arResult['PERSON_TYPE_IDS'], 'companySpecifiedClientFields' => $companySpecifiedClientFields, 'languageId' => LANGUAGE_ID, 'filesFieldSettings' => array('containerId' => $arResult['FILES_FIELD_CONTAINER_ID'], 'controlMode' => 'edit', 'webDavSelectUrl' => $arResult['WEBDAV_SELECT_URL'], 'webDavUploadUrl' => $arResult['WEBDAV_UPLOAD_URL'], 'webDavShowUrl' => $arResult['WEBDAV_SHOW_URL'], 'files' => $arResult['ELEMENT']['STORAGE_ELEMENT_IDS'], 'uploadContainerID' => $prefixLower . '_upload_container', 'uploadControlID' => $prefixLower . '_uploader', 'uploadInputID' => $prefixLower . '_saved_file', 'storageTypeId' => $arResult['ELEMENT']['STORAGE_TYPE_ID'], 'defaultStorageTypeId' => CCrmQuote::GetDefaultStorageTypeID(), 'serviceUrl' => '/bitrix/components/bitrix/crm.quote.edit/ajax.php?siteID=' . SITE_ID . '&' . bitrix_sessid_get(), 'messages' => array('webdavFileLoading' => GetMessage('CRM_QUOTE_WEBDAV_FILE_LOADING'), 'webdavFileAlreadyExists' => GetMessage('CRM_QUOTE_WEBDAV_FILE_ALREADY_EXISTS'), 'webdavFileAccessDenied' => GetMessage('CRM_QUOTE_WEBDAV_FILE_ACCESS_DENIED'), 'webdavAttachFile' => GetMessage('CRM_QUOTE_WEBDAV_ATTACH_FILE'), 'webdavTitle' => GetMessage('CRM_QUOTE_WEBDAV_TITLE'), 'webdavDragFile' => GetMessage('CRM_QUOTE_WEBDAV_DRAG_FILE'), 'webdavSelectFile' => GetMessage('CRM_QUOTE_WEBDAV_SELECT_FILE'), 'webdavSelectFromLib' => GetMessage('CRM_QUOTE_WEBDAV_SELECT_FROM_LIB'), 'webdavLoadFiles' => GetMessage('CRM_QUOTE_WEBDAV_LOAD_FILES'), 'diskAttachFiles' => GetMessage('CRM_QUOTE_DISK_ATTACH_FILE'), 'diskAttachedFiles' => GetMessage('CRM_QUOTE_DISK_ATTACHED_FILES'), 'diskSelectFile' => GetMessage('CRM_QUOTE_DISK_SELECT_FILE'), 'diskSelectFileLegend' => GetMessage('CRM_QUOTE_DISK_SELECT_FILE_LEGEND'), 'diskUploadFile' => GetMessage('CRM_QUOTE_DISK_UPLOAD_FILE'), 'diskUploadFileLegend' => GetMessage('CRM_QUOTE_DISK_UPLOAD_FILE_LEGEND')))); CCrmQuote::PrepareStorageElementInfo($arResult['ELEMENT']); if (isset($arResult['ELEMENT']['WEBDAV_ELEMENTS'])) { $editorSettings['filesFieldSettings']['webdavelements'] = $arResult['ELEMENT']['WEBDAV_ELEMENTS']; } elseif (isset($arResult['ELEMENT']['DISK_FILES'])) { $editorSettings['filesFieldSettings']['diskfiles'] = $arResult['ELEMENT']['DISK_FILES']; } ?> <script type="text/javascript"> window.CrmProductRowSetLocation = function(){ BX.onCustomEvent('CrmProductRowSetLocation', ['LOC_CITY']); } BX.ready(function(){ BX.CrmQuoteEditor.create(
$arResult['PREFIX'] = isset($arResult['PREFIX']) ? strval($arResult['PREFIX']) : 'crm_quote_show'; $activityEditorID = $arResult['PREFIX'] . '_send_email'; $activityEditorSettings = array('CONTAINER_ID' => '', 'EDITOR_ID' => $activityEditorID, 'PREFIX' => $arResult['PREFIX'], 'ENABLE_UI' => false, 'ENABLE_TOOLBAR' => false, 'ENABLE_EMAIL_ADD' => true); $leadID = isset($arResult['ELEMENT']['LEAD_ID']) ? intval($arResult['ELEMENT']['LEAD_ID']) : 0; if ($leadID > 0) { $activityEditorSettings['OWNER_TYPE'] = CCrmOwnerType::LeadName; $activityEditorSettings['OWNER_ID'] = $leadID; } $dealID = isset($arResult['ELEMENT']['DEAL_ID']) ? intval($arResult['ELEMENT']['DEAL_ID']) : 0; if ($dealID > 0) { $activityEditorSettings['OWNER_TYPE'] = CCrmOwnerType::DealName; $activityEditorSettings['OWNER_ID'] = $dealID; } $APPLICATION->IncludeComponent('bitrix:crm.activity.editor', '', $activityEditorSettings, $component, array('HIDE_ICONS' => 'Y')); $prefixLower = strtolower($arResult['PREFIX']); $scriptSettings = array('formId' => $arResult['FORM_ID'], 'enableInstantEdit' => (bool) $arResult['ENABLE_INSTANT_EDIT'], 'instantEditorId' => $instantEditorID, 'summaryContainerId' => $summaryContainerID, 'productRowsTabId' => $arResult['PRODUCT_ROW_TAB_ID'], 'ownerType' => CCrmQuote::OWNER_TYPE, 'ownerId' => $arResult['ELEMENT_ID'], 'url' => '/bitrix/components/bitrix/crm.quote.show/ajax.php?' . bitrix_sessid_get(), 'callToFormat' => CCrmCallToUrl::GetFormat(CCrmCallToUrl::Bitrix), 'messages' => array('editButtonTitle' => GetMessage('CRM_EDIT_BTN_TTL'), 'lockButtonTitle' => GetMessage('CRM_LOCK_BTN_TTL')), 'filesFieldSettings' => array('containerId' => $arResult['FILES_FIELD_CONTAINER_ID'], 'controlMode' => 'view', 'webDavSelectUrl' => $arResult['WEBDAV_SELECT_URL'], 'webDavUploadUrl' => $arResult['WEBDAV_UPLOAD_URL'], 'webDavShowUrl' => $arResult['WEBDAV_SHOW_URL'], 'files' => $arResult['ELEMENT']['STORAGE_ELEMENT_IDS'], 'uploadContainerID' => $prefixLower . '_upload_container', 'uploadControlID' => $prefixLower . '_uploader', 'uploadInputID' => $prefixLower . '_saved_file', 'storageTypeId' => $arResult['ELEMENT']['STORAGE_TYPE_ID'], 'defaultStorageTypeId' => CCrmQuote::GetDefaultStorageTypeID(), 'serviceUrl' => '/bitrix/components/bitrix/crm.quote.edit/ajax.php?siteID=' . SITE_ID . '&' . bitrix_sessid_get(), 'messages' => array('webdavFileLoading' => GetMessage('CRM_QUOTE_WEBDAV_FILE_LOADING'), 'webdavFileAlreadyExists' => GetMessage('CRM_QUOTE_WEBDAV_FILE_ALREADY_EXISTS'), 'webdavFileAccessDenied' => GetMessage('CRM_QUOTE_WEBDAV_FILE_ACCESS_DENIED'), 'webdavAttachFile' => GetMessage('CRM_QUOTE_WEBDAV_ATTACH_FILE'), 'webdavTitle' => GetMessage('CRM_QUOTE_WEBDAV_TITLE'), 'webdavDragFile' => GetMessage('CRM_QUOTE_WEBDAV_DRAG_FILE'), 'webdavSelectFile' => GetMessage('CRM_QUOTE_WEBDAV_SELECT_FILE'), 'webdavSelectFromLib' => GetMessage('CRM_QUOTE_WEBDAV_SELECT_FROM_LIB'), 'webdavLoadFiles' => GetMessage('CRM_QUOTE_WEBDAV_LOAD_FILES'), 'diskAttachedFiles' => GetMessage('CRM_QUOTE_DISK_ATTACHED_FILES')))); CCrmQuote::PrepareStorageElementInfo($arResult['ELEMENT']); if (isset($arResult['ELEMENT']['WEBDAV_ELEMENTS'])) { $scriptSettings['filesFieldSettings']['webdavelements'] = $arResult['ELEMENT']['WEBDAV_ELEMENTS']; } elseif (isset($arResult['ELEMENT']['DISK_FILES'])) { $scriptSettings['filesFieldSettings']['diskfiles'] = $arResult['ELEMENT']['DISK_FILES']; } ?> <script type="text/javascript"> BX.ready( function() { BX.CrmQuoteShowInitScript(<?php echo CUtil::PhpToJSObject($scriptSettings); ?> );