示例#1
0
 $currencyID = isset($data['CURRENCY_ID']) ? $data['CURRENCY_ID'] : '';
 if ($currencyID === '') {
     $currencyID = CCrmCurrency::GetBaseCurrencyID();
 }
 $fields['CURRENCY_ID'] = $currencyID;
 $productDataFieldName = 'PRODUCT_ROWS';
 $processProductRows = isset($data['PROCESS_PRODUCT_ROWS']) ? $data['PROCESS_PRODUCT_ROWS'] === 'Y' : false;
 $productRows = array();
 if ($processProductRows) {
     $productRows = isset($data[$productDataFieldName]) ? $data[$productDataFieldName] : array();
     if (!empty($productRows)) {
         foreach ($productRows as &$productRow) {
             $productRow['CUSTOMIZED'] = 'Y';
         }
         unset($productRow);
         $result = CCrmProductRow::CalculateTotalInfo('D', 0, false, $fields, $productRows);
         $fields['OPPORTUNITY'] = isset($result['OPPORTUNITY']) ? $result['OPPORTUNITY'] : 0.0;
         $fields['TAX_VALUE'] = isset($result['TAX_VALUE']) ? $result['TAX_VALUE'] : 0.0;
     }
 }
 $assignedByID = isset($data['ASSIGNED_BY_ID']) ? intval($data['ASSIGNED_BY_ID']) : 0;
 if ($assignedByID <= 0) {
     $assignedByID = intval($curUser->GetID());
 }
 $fields['ASSIGNED_BY_ID'] = $assignedByID;
 $entity = new CCrmDeal(false);
 if (!$entity->CheckFields($fields, !$isNew ? $ID : false, array('DISABLE_USER_FIELD_CHECK' => true))) {
     __CrmMobileDealEditEndResonse(array('ERROR' => strip_tags(preg_replace("/<br[^>]*>/", "\n", $entity->LAST_ERROR))));
 } else {
     //$DB->StartTransaction();
     $successed = false;
示例#2
0
 public function SynchronizeProductRows($ID)
 {
     $arTotalInfo = CCrmProductRow::CalculateTotalInfo(CCrmQuote::OWNER_TYPE, $ID);
     if (is_array($arTotalInfo)) {
         $arFields = array('OPPORTUNITY' => isset($arTotalInfo['OPPORTUNITY']) ? $arTotalInfo['OPPORTUNITY'] : 0.0, 'TAX_VALUE' => isset($arTotalInfo['TAX_VALUE']) ? $arTotalInfo['TAX_VALUE'] : 0.0);
         $entity = new CCrmQuote();
         $entity->Update($ID, $arFields);
     }
 }
示例#3
0
 if ($currencyID === '') {
     $currencyID = CCrmCurrency::GetBaseCurrencyID();
 }
 $fields['CURRENCY_ID'] = $currencyID;
 $productDataFieldName = 'PRODUCT_ROWS';
 $processProductRows = isset($data['PROCESS_PRODUCT_ROWS']) ? $data['PROCESS_PRODUCT_ROWS'] === 'Y' : false;
 $productRows = array();
 if ($processProductRows) {
     $productRows = isset($data[$productDataFieldName]) ? $data[$productDataFieldName] : array();
     if (!empty($productRows)) {
         foreach ($productRows as &$productRow) {
             $productRow['CUSTOMIZED'] = 'Y';
         }
         unset($productRow);
         $params = array('CONTACT_ID' => 0, 'COMPANY_ID' => 0, 'CURRENCY_ID' => $fields['CURRENCY_ID']);
         $result = CCrmProductRow::CalculateTotalInfo('L', 0, false, $params, $productRows);
         $fields['OPPORTUNITY'] = isset($result['OPPORTUNITY']) ? $result['OPPORTUNITY'] : 0.0;
     }
 }
 $assignedByID = isset($data['ASSIGNED_BY_ID']) ? intval($data['ASSIGNED_BY_ID']) : 0;
 if ($assignedByID <= 0) {
     $assignedByID = intval($curUser->GetID());
 }
 $fields['ASSIGNED_BY_ID'] = $assignedByID;
 if (isset($data['FM']) && is_array($data['FM']) && !empty($data['FM'])) {
     $fields['FM'] = $data['FM'];
 }
 $entity = new CCrmLead(false);
 if (!$entity->CheckFields($fields, !$isNew ? $ID : false, array('DISABLE_USER_FIELD_CHECK' => true))) {
     __CrmMobileLeadEditEndResonse(array('ERROR' => strip_tags(preg_replace("/<br[^>]*>/", "\n", $entity->LAST_ERROR))));
 } else {
示例#4
0
     } elseif (CCrmCompany::CheckReadPermission($companyID)) {
         $arFields['COMPANY_ID'] = $companyID;
     } elseif (isset($arSrcElement['COMPANY_ID'])) {
         $arFields['COMPANY_ID'] = $arSrcElement['COMPANY_ID'];
     }
 } elseif (isset($arSrcElement['COMPANY_ID'])) {
     $arFields['COMPANY_ID'] = $arSrcElement['COMPANY_ID'];
 }
 $processProductRows = array_key_exists($productDataFieldName, $_POST);
 $arProd = array();
 if ($processProductRows) {
     $prodJson = isset($_POST[$productDataFieldName]) ? strval($_POST[$productDataFieldName]) : '';
     $arProd = $arResult['PRODUCT_ROWS'] = strlen($prodJson) > 0 ? CUtil::JsObjectToPhp($prodJson) : array();
     if (count($arProd) > 0) {
         // SYNC OPPORTUNITY WITH PRODUCT ROW SUM TOTAL
         $result = CCrmProductRow::CalculateTotalInfo('D', 0, false, $arFields, $arProd);
         $arFields['OPPORTUNITY'] = isset($result['OPPORTUNITY']) ? $result['OPPORTUNITY'] : 1.0;
         $arFields['TAX_VALUE'] = isset($result['TAX_VALUE']) ? $result['TAX_VALUE'] : 0.0;
     }
 }
 // Product row settings
 $productRowSettings = array();
 $productRowSettingsFieldName = $productDataFieldName . '_SETTINGS';
 if (array_key_exists($productRowSettingsFieldName, $_POST)) {
     $settingsJson = isset($_POST[$productRowSettingsFieldName]) ? strval($_POST[$productRowSettingsFieldName]) : '';
     $arSettings = strlen($settingsJson) > 0 ? CUtil::JsObjectToPhp($settingsJson) : array();
     if (is_array($arSettings)) {
         $productRowSettings['ENABLE_DISCOUNT'] = isset($arSettings['ENABLE_DISCOUNT']) ? $arSettings['ENABLE_DISCOUNT'] === 'Y' : false;
         $productRowSettings['ENABLE_TAX'] = isset($arSettings['ENABLE_TAX']) ? $arSettings['ENABLE_TAX'] === 'Y' : false;
     }
 }
示例#5
0
 public function executePhase()
 {
     if ($this->currentPhase === LeadConversionPhase::COMPANY_CREATION || $this->currentPhase === LeadConversionPhase::CONTACT_CREATION || $this->currentPhase === LeadConversionPhase::DEAL_CREATION) {
         if ($this->currentPhase === LeadConversionPhase::COMPANY_CREATION) {
             $entityTypeID = \CCrmOwnerType::Company;
         } elseif ($this->currentPhase === LeadConversionPhase::CONTACT_CREATION) {
             $entityTypeID = \CCrmOwnerType::Contact;
         } else {
             $entityTypeID = \CCrmOwnerType::Deal;
         }
         $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::Company) {
                 if (!\CCrmCompany::Exists($entityID)) {
                     throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Company, EntityConversionException::TARG_DST, EntityConversionException::NOT_FOUND);
                 }
                 $entity = new \CCrmCompany(false);
             } elseif ($entityTypeID === \CCrmOwnerType::Contact) {
                 if (!\CCrmContact::Exists($entityID)) {
                     throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Contact, EntityConversionException::TARG_DST, EntityConversionException::NOT_FOUND);
                 }
                 $entity = new \CCrmContact(false);
             } else {
                 if (!\CCrmDeal::Exists($entityID)) {
                     throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Deal, EntityConversionException::TARG_DST, EntityConversionException::NOT_FOUND);
                 }
                 $entity = new \CCrmDeal(false);
             }
             if (!\CCrmAuthorizationHelper::CheckUpdatePermission($entityTypeName, $entityID, $permissions)) {
                 throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::UPDATE_DENIED);
             }
             $fields = array('LEAD_ID' => $this->entityID);
             $entity->Update($entityID, $fields);
             $this->resultData[$entityTypeName] = $entityID;
             return true;
         }
         if (!\CCrmAuthorizationHelper::CheckCreatePermission($entityTypeName, $permissions)) {
             throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::CREATE_DENIED);
         }
         if (UserFieldSynchronizer::needForSynchronization(\CCrmOwnerType::Lead, $entityTypeID)) {
             throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::NOT_SYNCHRONIZED);
         }
         if (!ConversionSettings::getCurrent()->isAutocreationEnabled()) {
             throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::AUTOCREATION_DISABLED);
         }
         if (\CCrmBizProcHelper::HasAutoWorkflows($entityTypeID, \CCrmBizProcEventType::Create)) {
             throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::HAS_WORKFLOWS);
         }
         /** @var LeadConversionMapper $mapper */
         $mapper = $this->getMapper();
         $map = self::prepareMap($entityTypeID);
         $fields = $mapper->map($map);
         if (empty($fields)) {
             throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::EMPTY_FIELDS);
         }
         if ($entityTypeID === \CCrmOwnerType::Company) {
             $entity = new \CCrmCompany(false);
             $entityID = $entity->Add($fields);
             if ($entityID <= 0) {
                 throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Company, EntityConversionException::TARG_DST, EntityConversionException::CREATE_FAILED, $entity->LAST_ERROR);
             }
             //region BizProcess
             $arErrors = array();
             \CCrmBizProcHelper::AutoStartWorkflows(\CCrmOwnerType::Company, $entityID, \CCrmBizProcEventType::Create, $arErrors);
             //endregion
             $this->resultData[\CCrmOwnerType::CompanyName] = $entityID;
         } elseif ($entityTypeID === \CCrmOwnerType::Contact) {
             if (isset($this->resultData[\CCrmOwnerType::CompanyName])) {
                 $fields['COMPANY_ID'] = $this->resultData[\CCrmOwnerType::CompanyName];
             }
             $entity = new \CCrmContact(false);
             if (!$entity->CheckFields($fields)) {
                 throw new EntityConversionException(\CCrmOwnerType::Lead, $entityTypeID, EntityConversionException::TARG_DST, EntityConversionException::INVALID_FIELDS, $entity->LAST_ERROR);
             }
             $entityID = $entity->Add($fields);
             if ($entityID <= 0) {
                 throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Contact, EntityConversionException::TARG_DST, EntityConversionException::CREATE_FAILED, $entity->LAST_ERROR);
             }
             //region BizProcess
             $arErrors = array();
             \CCrmBizProcHelper::AutoStartWorkflows(\CCrmOwnerType::Contact, $entityID, \CCrmBizProcEventType::Create, $arErrors);
             //endregion
             $this->resultData[\CCrmOwnerType::ContactName] = $entityID;
         } else {
             if (isset($this->resultData[\CCrmOwnerType::ContactName])) {
                 $fields['CONTACT_ID'] = $this->resultData[\CCrmOwnerType::ContactName];
             }
             if (isset($this->resultData[\CCrmOwnerType::CompanyName])) {
                 $fields['COMPANY_ID'] = $this->resultData[\CCrmOwnerType::CompanyName];
             }
             $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;
             }
             $entity = new \CCrmDeal(false);
             $entityID = $entity->Add($fields);
             if ($entityID <= 0) {
                 throw new EntityConversionException(\CCrmOwnerType::Lead, \CCrmOwnerType::Deal, EntityConversionException::TARG_DST, EntityConversionException::CREATE_FAILED, $entity->LAST_ERROR);
             }
             if (!empty($productRows)) {
                 \CCrmDeal::SaveProductRows($entityID, $productRows, false, false, false);
             }
             //region BizProcess
             $arErrors = array();
             \CCrmBizProcHelper::AutoStartWorkflows(\CCrmOwnerType::Deal, $entityID, \CCrmBizProcEventType::Create, $arErrors);
             //endregion
             $this->resultData[\CCrmOwnerType::DealName] = $entityID;
         }
         return true;
     } elseif ($this->currentPhase === LeadConversionPhase::FINALIZATION) {
         $result = \CCrmLead::GetListEx(array(), array('=ID' => $this->entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('STATUS_ID'));
         $presentFields = is_object($result) ? $result->Fetch() : null;
         if (is_array($presentFields)) {
             $fields = array();
             $statusID = isset($presentFields['STATUS_ID']) ? $presentFields['STATUS_ID'] : '';
             if ($statusID !== 'CONVERTED') {
                 $fields['STATUS_ID'] = 'CONVERTED';
             }
             if (isset($this->resultData[\CCrmOwnerType::CompanyName])) {
                 $fields['COMPANY_ID'] = $this->resultData[\CCrmOwnerType::CompanyName];
             }
             if (isset($this->resultData[\CCrmOwnerType::ContactName])) {
                 $fields['CONTACT_ID'] = $this->resultData[\CCrmOwnerType::ContactName];
             }
             if (!empty($fields)) {
                 $entity = new \CCrmLead(false);
                 if ($entity->Update($this->entityID, $fields)) {
                     //region BizProcess
                     $arErrors = array();
                     \CCrmBizProcHelper::AutoStartWorkflows(\CCrmOwnerType::Lead, $this->entityID, \CCrmBizProcEventType::Edit, $arErrors);
                     //endregion
                 }
             }
         }
         return true;
     }
     return false;
 }
示例#6
0
 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;
 }