$USER_FIELD_MANAGER->EditFormAddFields(CCrmQuote::$sUFEntityID, $arFields); $arResult['ERROR_MESSAGE'] = ''; if (!$CCrmQuote->CheckFields($arFields, $bEdit ? $arResult['ELEMENT']['ID'] : false)) { if (!empty($CCrmQuote->LAST_ERROR)) { $arResult['ERROR_MESSAGE'] .= $CCrmQuote->LAST_ERROR; } else { $arResult['ERROR_MESSAGE'] .= GetMessage('UNKNOWN_ERROR'); } } /*---bizproc---if (($arBizProcParametersValues = $CCrmBizProc->CheckFields($bEdit ? $arResult['ELEMENT']['ID']: false, false, $arResult['ELEMENT']['ASSIGNED_BY'], $bEdit ? $arEntityAttr[$arResult['ELEMENT']['ID']] : array())) === false) $arResult['ERROR_MESSAGE'] .= $CCrmBizProc->LAST_ERROR;*/ if (empty($arResult['ERROR_MESSAGE'])) { $DB->StartTransaction(); $bSuccess = false; if ($bEdit) { $bSuccess = $CCrmQuote->Update($arResult['ELEMENT']['ID'], $arFields, true, true, array('REGISTER_SONET_EVENT' => true)); } else { /*if ($originatorId > 0 && $originId > 0) { $arFields['ORIGINATOR_ID'] = $originatorId; $arFields['ORIGIN_ID'] = $originId; }*/ $ID = $CCrmQuote->Add($arFields, true, array('REGISTER_SONET_EVENT' => false)); $bSuccess = $ID !== false; if ($bSuccess) { $arResult['ELEMENT']['ID'] = $ID; } } if ($bSuccess) { // Save settings if (is_array($productRowSettings) && count($productRowSettings) > 0) {
if ($CCrmDeal->Update($entityID, $arField)) { $arErrors = array(); CCrmBizProcHelper::AutoStartWorkflows(CCrmOwnerType::Deal, $entityID, CCrmBizProcEventType::Edit, $arErrors); } } } break; case 'QUOTE': if (isset($_POST['STATUS_ID'])) { $statusID = $_POST['STATUS_ID']; $dbResult = CCrmQuote::GetList(array(), array('=ID' => $entityID), false, false, array('STATUS_ID')); $arPrevious = $dbResult ? $dbResult->Fetch() : null; if (is_array($arPrevious) && isset($arPrevious['STATUS_ID']) && $arPrevious['STATUS_ID'] !== $statusID) { $CCrmDeal = new CCrmQuote(); $arField = array('STATUS_ID' => $statusID); if ($CCrmDeal->Update($entityID, $arField)) { $arErrors = array(); CCrmBizProcHelper::AutoStartWorkflows(CCrmOwnerType::Quote, $entityID, CCrmBizProcEventType::Edit, $arErrors); } } } break; } } } else { $arResult['FORM_ID'] = isset($arParams['FORM_ID']) ? $arParams['FORM_ID'] : ''; $arResult['FORM_TYPE'] = $arParams['FORM_TYPE']; $arResult['ENTITY_TYPE'] = $arParams['ENTITY_TYPE']; $arResult['ENTITY_ID'] = intval($arParams['ENTITY_ID']); $arResult['ENTITY_TITLE'] = GetMessage('CRM_EVENT_DEFAULT_TITLE'); $arResult['EVENT_TYPE'] = $arParams['EVENT_TYPE'];
public static function HandleStorageElementDeletion($storageTypeID, $elementID) { global $DB; $storageTypeID = (int) $storageTypeID; $elementID = (int) $elementID; $dbResult = $DB->Query('SELECT QUOTE_ID FROM ' . CCrmQuote::ELEMENT_TABLE_NAME . ' WHERE STORAGE_TYPE_ID = ' . $storageTypeID . ' AND ELEMENT_ID = ' . $elementID, false, 'File: ' . __FILE__ . '<br/>Line: ' . __LINE__); while ($arResult = $dbResult->Fetch()) { $entityID = isset($arResult['QUOTE_ID']) ? (int) $arResult['QUOTE_ID'] : 0; if ($entityID <= 0) { continue; } $dbEntity = self::GetList(array(), array('ID' => $entityID), false, array('nTopCount' => 1), array('STORAGE_TYPE_ID', 'STORAGE_ELEMENT_IDS')); $arEntity = $dbEntity->Fetch(); if (!is_array($arEntity)) { continue; } $arEntity['STORAGE_TYPE_ID'] = isset($arEntity['STORAGE_TYPE_ID']) ? (int) $arEntity['STORAGE_TYPE_ID'] : $storageTypeID; self::PrepareStorageElementIDs($arEntity); if (!empty($arEntity['STORAGE_ELEMENT_IDS'])) { $arEntity['STORAGE_ELEMENT_IDS'] = array_diff($arEntity['STORAGE_ELEMENT_IDS'], array($elementID)); } $quote = new CCrmQuote(false); $quote->Update($entityID, $arEntity, true, false); } }
die; } $fieldValues = array(); if (isset($_POST['FIELD_VALUE'])) { if (is_array($_POST['FIELD_VALUE'])) { $fieldValues = $_POST['FIELD_VALUE']; } else { $fieldValues[] = $_POST['FIELD_VALUE']; } } $dbResult = CCrmQuote::GetList(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*')); $arFields = is_object($dbResult) ? $dbResult->Fetch() : null; if (is_array($arFields)) { CCrmInstantEditorHelper::PrepareUpdate(CCrmOwnerType::Quote, $arFields, $fieldNames, $fieldValues); $CCrmQuote = new CCrmQuote(); if ($CCrmQuote->Update($ID, $arFields, true, true, array('REGISTER_SONET_EVENT' => true))) { /*---bizproc---$arErrors = array(); CCrmBizProcHelper::AutoStartWorkflows( CCrmOwnerType::Quote, $ID, CCrmBizProcEventType::Edit, $arErrors );*/ } } } if ($mode === 'GET_USER_SELECTOR') { if (!CCrmQuote::CheckUpdatePermission(0, $currentUserPermissions)) { __CrmQuoteShowEndHtmlResonse(); } $name = isset($_POST['NAME']) ? $_POST['NAME'] : '';
if (isset($actionData['FIELDS']) && is_array($actionData['FIELDS'])) { foreach ($actionData['FIELDS'] as $ID => $arSrcData) { $arEntityAttr = $CCrmPerms->GetEntityAttr('QUOTE', array($ID)); if (!$CCrmPerms->CheckEnityAccess('QUOTE', 'WRITE', $arEntityAttr[$ID])) { continue; } $arUpdateData = array(); reset($arResult['HEADERS']); foreach ($arResult['HEADERS'] as $arHead) { if (isset($arHead['editable']) && $arHead['editable'] == true && isset($arSrcData[$arHead['id']])) { $arUpdateData[$arHead['id']] = $arSrcData[$arHead['id']]; } } if (!empty($arUpdateData)) { $DB->StartTransaction(); if ($CCrmQuote->Update($ID, $arUpdateData, true, true, array('DISABLE_USER_FIELD_CHECK' => true))) { $DB->Commit(); /*---bizproc---$arErrors = array(); CCrmBizProcHelper::AutoStartWorkflows( CCrmOwnerType::Quote, $ID, CCrmBizProcEventType::Edit, $arErrors );*/ } else { $DB->Rollback(); } } } } } elseif ($actionData['NAME'] == 'tasks') {
echo CUtil::PhpToJSObject(array('ERROR' => 'Not found!')); die; } if (isset($arFields['CREATED_BY_ID'])) { unset($arFields['CREATED_BY_ID']); } if (isset($arFields['DATE_CREATE'])) { unset($arFields['DATE_CREATE']); } if (isset($arFields['MODIFY_BY_ID'])) { unset($arFields['MODIFY_BY_ID']); } if (isset($arFields['DATE_MODIFY'])) { unset($arFields['DATE_MODIFY']); } $arFields['STATUS_ID'] = $statusID; $CCrmQuote = new CCrmQuote(false); if ($CCrmQuote->Update($ID, $arFields, true, true, array('DISABLE_USER_FIELD_CHECK' => true, 'REGISTER_SONET_EVENT' => true))) { /*---bizproc---$arErrors = array(); CCrmBizProcHelper::AutoStartWorkflows( CCrmOwnerType::Quote, $ID, CCrmBizProcEventType::Edit, $arErrors );*/ } $APPLICATION->RestartBuffer(); Header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); echo CUtil::PhpToJsObject(array('TYPE' => $targetTypeName, 'ID' => $ID, 'VALUE' => $statusID)); die; }
public function executePhase() { if ($this->currentPhase === DealConversionPhase::INVOICE_CREATION || $this->currentPhase === DealConversionPhase::QUOTE_CREATION) { if ($this->currentPhase === DealConversionPhase::INVOICE_CREATION) { $entityTypeID = \CCrmOwnerType::Invoice; } else { $entityTypeID = \CCrmOwnerType::Quote; } $entityTypeName = \CCrmOwnerType::ResolveName($entityTypeID); $config = $this->config->getItem($entityTypeID); if (!$config->isActive()) { return false; } /** @var \CCrmPerms $permissions */ $permissions = $this->getUserPermissions(); $entityID = isset($this->contextData[$entityTypeName]) ? $this->contextData[$entityTypeName] : 0; if ($entityID > 0) { if ($entityTypeID === \CCrmOwnerType::Invoice) { if (!\CCrmInvoice::Exists($entityID)) { throw new EntityConversionException(\CCrmOwnerType::Deal, \CCrmOwnerType::Invoice, EntityConversionException::TARG_DST, EntityConversionException::NOT_FOUND); } if (!\CCrmInvoice::CheckUpdatePermission($entityID, $permissions)) { throw new EntityConversionException(\CCrmOwnerType::Deal, \CCrmOwnerType::Invoice, EntityConversionException::TARG_DST, EntityConversionException::UPDATE_DENIED); } $entity = new \CCrmInvoice(false); $fields = array('UF_DEAL_ID' => $this->entityID); try { $entity->Update($entityID, $fields); } catch (Main\DB\SqlQueryException $e) { } $this->resultData[$entityTypeName] = $entityID; } else { if (!\CCrmQuote::Exists($entityID)) { throw new EntityConversionException(\CCrmOwnerType::Deal, \CCrmOwnerType::Quote, EntityConversionException::TARG_DST, EntityConversionException::NOT_FOUND); } if (!\CCrmQuote::CheckUpdatePermission($entityID, $permissions)) { throw new EntityConversionException(\CCrmOwnerType::Deal, \CCrmOwnerType::Quote, EntityConversionException::TARG_DST, EntityConversionException::UPDATE_DENIED); } $entity = new \CCrmQuote(false); $fields = array('DEAL_ID' => $this->entityID); $entity->Update($entityID, $fields); $this->resultData[$entityTypeName] = $entityID; } return true; } if (!\CCrmAuthorizationHelper::CheckCreatePermission($entityTypeName, $permissions)) { throw new EntityConversionException(\CCrmOwnerType::Deal, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::CREATE_DENIED); } if (UserFieldSynchronizer::needForSynchronization(\CCrmOwnerType::Deal, $entityTypeID)) { throw new EntityConversionException(\CCrmOwnerType::Deal, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::NOT_SYNCHRONIZED); } if (!ConversionSettings::getCurrent()->isAutocreationEnabled()) { throw new EntityConversionException(\CCrmOwnerType::Deal, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::AUTOCREATION_DISABLED); } /** @var DealConversionMapper $mapper */ $mapper = $this->getMapper(); $map = self::prepareMap($entityTypeID); $fields = $mapper->map($map); if (empty($fields)) { throw new EntityConversionException(\CCrmOwnerType::Deal, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::EMPTY_FIELDS); } if ($entityTypeID === \CCrmOwnerType::Invoice) { $entity = new \CCrmInvoice(false); if (!$entity->CheckFields($fields)) { throw new EntityConversionException(\CCrmOwnerType::Deal, \CCrmOwnerType::Invoice, EntityConversionException::TARG_DST, EntityConversionException::INVALID_FIELDS, $entity->LAST_ERROR); } $entityID = $entity->Add($fields); if ($entityID <= 0) { throw new EntityConversionException(\CCrmOwnerType::Deal, \CCrmOwnerType::Invoice, EntityConversionException::TARG_DST, EntityConversionException::CREATE_FAILED, $entity->LAST_ERROR); } $this->resultData[\CCrmOwnerType::InvoiceName] = $entityID; } else { $entity = new \CCrmQuote(false); if (!$entity->CheckFields($fields)) { throw new EntityConversionException(\CCrmOwnerType::Deal, \CCrmOwnerType::Quote, EntityConversionException::TARG_DST, EntityConversionException::INVALID_FIELDS, $entity->LAST_ERROR); } $productRows = isset($fields['PRODUCT_ROWS']) && is_array($fields['PRODUCT_ROWS']) ? $fields['PRODUCT_ROWS'] : array(); if (!empty($productRows)) { $currencyID = isset($fields['CURRENCY_ID']) ? $fields['CURRENCY_ID'] : ''; $personTypes = \CCrmPaySystem::getPersonTypeIDs(); $personTypeID = 0; if (isset($personTypes['COMPANY']) && isset($personTypes['CONTACT'])) { if (isset($fields['COMPANY_ID']) && $fields['COMPANY_ID'] > 0) { $personTypeID = $personTypes['COMPANY']; } elseif (isset($fields['CONTACT_ID']) && $fields['CONTACT_ID'] > 0) { $personTypeID = $personTypes['CONTACT']; } } if ($currencyID !== '' && $personTypeID > 0) { $calculationOptions = array(); if (\CCrmTax::isTaxMode() && isset($fields['LOCATION_ID'])) { $calculationOptions['LOCATION_ID'] = $fields['LOCATION_ID']; } $result = \CCrmSaleHelper::Calculate($productRows, $currencyID, $personTypeID, false, SITE_ID, $calculationOptions); $arFields['OPPORTUNITY'] = isset($result['PRICE']) ? round(doubleval($result['PRICE']), 2) : 1.0; $arFields['TAX_VALUE'] = isset($result['TAX_VALUE']) ? round(doubleval($result['TAX_VALUE']), 2) : 0.0; } } $entityID = $entity->Add($fields); if ($entityID <= 0) { throw new EntityConversionException(\CCrmOwnerType::Deal, \CCrmOwnerType::Quote, EntityConversionException::TARG_DST, EntityConversionException::CREATE_FAILED, $entity->LAST_ERROR); } $this->resultData[\CCrmOwnerType::QuoteName] = $entityID; } return true; } elseif ($this->currentPhase === DealConversionPhase::FINALIZATION) { return true; } return false; }
public function executePhase() { if ($this->currentPhase === QuoteConversionPhase::DEAL_CREATION || $this->currentPhase === QuoteConversionPhase::INVOICE_CREATION) { if ($this->currentPhase === QuoteConversionPhase::DEAL_CREATION) { $entityTypeID = \CCrmOwnerType::Deal; } else { $entityTypeID = \CCrmOwnerType::Invoice; } $entityTypeName = \CCrmOwnerType::ResolveName($entityTypeID); $config = $this->config->getItem($entityTypeID); if (!$config->isActive()) { return false; } /** @var \CCrmPerms $permissions */ $permissions = $this->getUserPermissions(); $entityID = isset($this->contextData[$entityTypeName]) ? $this->contextData[$entityTypeName] : 0; if ($entityID > 0) { if ($entityTypeID === \CCrmOwnerType::Deal) { if (!\CCrmDeal::Exists($entityID)) { throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Deal, EntityConversionException::TARG_DST, EntityConversionException::NOT_FOUND); } $this->resultData[$entityTypeName] = $entityID; } else { if (!\CCrmInvoice::Exists($entityID)) { throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Invoice, EntityConversionException::TARG_DST, EntityConversionException::NOT_FOUND); } if (!\CCrmInvoice::CheckUpdatePermission($entityID, $permissions)) { throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Invoice, EntityConversionException::TARG_DST, EntityConversionException::UPDATE_DENIED); } $entity = new \CCrmInvoice(false); $fields = array('UF_QUOTE_ID' => $this->entityID); try { $entity->Update($entityID, $fields); } catch (Main\DB\SqlQueryException $e) { } $this->resultData[$entityTypeName] = $entityID; } return true; } if (!\CCrmAuthorizationHelper::CheckCreatePermission($entityTypeName, $permissions)) { throw new EntityConversionException(\CCrmOwnerType::Quote, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::CREATE_DENIED); } if (UserFieldSynchronizer::needForSynchronization(\CCrmOwnerType::Quote, $entityTypeID)) { throw new EntityConversionException(\CCrmOwnerType::Quote, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::NOT_SYNCHRONIZED); } if (!ConversionSettings::getCurrent()->isAutocreationEnabled()) { throw new EntityConversionException(\CCrmOwnerType::Quote, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::AUTOCREATION_DISABLED); } if ($entityTypeID === \CCrmOwnerType::Deal && \CCrmBizProcHelper::HasAutoWorkflows($entityTypeID, \CCrmBizProcEventType::Create)) { throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::HAS_WORKFLOWS); } /** @var QuoteConversionMapper $mapper */ $mapper = $this->getMapper(); $map = self::prepareMap($entityTypeID); $fields = $mapper->map($map); if (empty($fields)) { throw new EntityConversionException(\CCrmOwnerType::Quote, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::EMPTY_FIELDS); } if ($entityTypeID === \CCrmOwnerType::Deal) { $entity = new \CCrmDeal(false); if (!$entity->CheckFields($fields)) { throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Deal, EntityConversionException::TARG_DST, EntityConversionException::INVALID_FIELDS, $entity->LAST_ERROR); } $productRows = isset($fields['PRODUCT_ROWS']) && is_array($fields['PRODUCT_ROWS']) ? $fields['PRODUCT_ROWS'] : array(); if (!empty($productRows)) { $result = \CCrmProductRow::CalculateTotalInfo('D', 0, false, $fields, $productRows); $fields['OPPORTUNITY'] = isset($result['OPPORTUNITY']) ? $result['OPPORTUNITY'] : 1.0; $fields['TAX_VALUE'] = isset($result['TAX_VALUE']) ? $result['TAX_VALUE'] : 0.0; } $entityID = $entity->Add($fields); if ($entityID <= 0) { throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Deal, EntityConversionException::TARG_DST, EntityConversionException::CREATE_FAILED, $entity->LAST_ERROR); } if (!empty($productRows)) { \CCrmDeal::SaveProductRows($entityID, $productRows, false, false, false); } $this->resultData[\CCrmOwnerType::DealName] = $entityID; } else { $entity = new \CCrmInvoice(false); if (!$entity->CheckFields($fields)) { throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Invoice, EntityConversionException::TARG_DST, EntityConversionException::INVALID_FIELDS, $entity->LAST_ERROR); } $entityID = $entity->Add($fields); if ($entityID <= 0) { throw new EntityConversionException(\CCrmOwnerType::Quote, \CCrmOwnerType::Invoice, EntityConversionException::TARG_DST, EntityConversionException::CREATE_FAILED, $entity->LAST_ERROR); } $this->resultData[\CCrmOwnerType::InvoiceName] = $entityID; } return true; } elseif ($this->currentPhase === DealConversionPhase::FINALIZATION) { $fields = array(); if (isset($this->resultData[\CCrmOwnerType::DealName])) { $fields['DEAL_ID'] = $this->resultData[\CCrmOwnerType::DealName]; } if (!empty($fields)) { $entity = new \CCrmQuote(false); $entity->Update($this->entityID, $fields); } return true; } return false; }