Esempio n. 1
0
     }
     if ($itemQty > 0) {
         CCrmQuote::RebuildEntityAccessAttrs($itemIDs);
         $progressData['TOTAL_ITEMS'] = $totalItemQty;
         $processedItemQty += $itemQty;
         $progressData['PROCESSED_ITEMS'] = $processedItemQty;
         $progressData['LAST_ITEM_ID'] = $itemIDs[$itemQty - 1];
         COption::SetOptionString('crm', '~CRM_REBUILD_QUOTE_ATTR_PROGRESS', serialize($progressData));
         __CrmConfigPermsEndResonse(array('STATUS' => 'PROGRESS', 'PROCESSED_ITEMS' => $processedItemQty, 'TOTAL_ITEMS' => $totalItemQty, 'SUMMARY' => GetMessage('CRM_CONFIG_PERMS_REBUILD_ATTR_PROGRESS_SUMMARY', array('#PROCESSED_ITEMS#' => $processedItemQty, '#TOTAL_ITEMS#' => $totalItemQty))));
     } else {
         COption::RemoveOption('crm', '~CRM_REBUILD_QUOTE_ATTR');
         COption::RemoveOption('crm', '~CRM_REBUILD_QUOTE_ATTR_PROGRESS');
         __CrmConfigPermsEndResonse(array('STATUS' => 'COMPLETED', 'PROCESSED_ITEMS' => $processedItemQty, 'TOTAL_ITEMS' => $totalItemQty, 'SUMMARY' => GetMessage('CRM_CONFIG_PERMS_REBUILD_ATTR_COMPLETED_SUMMARY', array('#PROCESSED_ITEMS#' => $processedItemQty))));
     }
 } elseif ($entityTypeID === CCrmOwnerType::Invoice) {
     if (!CCrmInvoice::CheckUpdatePermission(0)) {
         __CrmConfigPermsEndResonse(array('ERROR' => 'Access denied.'));
     }
     if (COption::GetOptionString('crm', '~CRM_REBUILD_INVOICE_ATTR', 'N') !== 'Y') {
         __CrmConfigPermsEndResonse(array('STATUS' => 'NOT_REQUIRED', 'SUMMARY' => GetMessage('CRM_CONFIG_PERMS_REBUILD_ATTR_NOT_REQUIRED_SUMMARY')));
     }
     $progressData = COption::GetOptionString('crm', '~CRM_REBUILD_INVOICE_ATTR_PROGRESS', '');
     $progressData = $progressData !== '' ? unserialize($progressData) : array();
     $lastItemID = isset($progressData['LAST_ITEM_ID']) ? intval($progressData['LAST_ITEM_ID']) : 0;
     $processedItemQty = isset($progressData['PROCESSED_ITEMS']) ? intval($progressData['PROCESSED_ITEMS']) : 0;
     $totalItemQty = isset($progressData['TOTAL_ITEMS']) ? intval($progressData['TOTAL_ITEMS']) : 0;
     if ($totalItemQty <= 0) {
         $totalItemQty = CCrmInvoice::GetList(array(), array('CHECK_PERMISSIONS' => 'N'), array(), false);
     }
     $filter = array('CHECK_PERMISSIONS' => 'N');
     if ($lastItemID > 0) {
Esempio n. 2
0
 public static function GetEditUrl($typeID, $ID, $bCheckPermissions = false)
 {
     $typeID = intval($typeID);
     $ID = intval($ID);
     if ($ID <= 0) {
         $ID = 0;
     }
     switch ($typeID) {
         case self::Lead:
             if ($bCheckPermissions && !($ID > 0 ? CCrmLead::CheckUpdatePermission($ID) : CCrmLead::CheckCreatePermission())) {
                 return '';
             }
             return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_edit'), array('lead_id' => $ID));
         case self::Contact:
             if ($bCheckPermissions && !($ID > 0 ? CCrmContact::CheckUpdatePermission($ID) : CCrmContact::CheckCreatePermission())) {
                 return '';
             }
             return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_contact_edit'), array('contact_id' => $ID));
         case self::Company:
             if ($bCheckPermissions && !($ID > 0 ? CCrmCompany::CheckUpdatePermission($ID) : CCrmCompany::CheckCreatePermission())) {
                 return '';
             }
             return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_company_edit'), array('company_id' => $ID));
         case self::Deal:
             if ($bCheckPermissions && !($ID > 0 ? CCrmDeal::CheckUpdatePermission($ID) : CCrmDeal::CheckCreatePermission())) {
                 return '';
             }
             return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_edit'), array('deal_id' => $ID));
         case self::Invoice:
             if ($bCheckPermissions && !($ID > 0 ? CCrmInvoice::CheckUpdatePermission($ID) : CCrmInvoice::CheckCreatePermission())) {
                 return '';
             }
             return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_invoice_edit'), array('invoice_id' => $ID));
         case self::Quote:
             if ($bCheckPermissions && !($ID > 0 ? CCrmQuote::CheckUpdatePermission($ID) : CCrmQuote::CheckCreatePermission())) {
                 return '';
             }
             return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_quote_edit'), array('quote_id' => $ID));
         case self::Activity:
             return CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_activity_edit'), array('activity_id' => $ID));
         default:
             return '';
     }
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
    if ($currencyID === '') {
        $currencyID = CCrmCurrency::GetBaseCurrencyID();
    }
    __CrmInvoiceShowEndJsonResonse(array('FORMATTED_SUM' => CCrmCurrency::MoneyToString($sum, $currencyID, '#'), 'FORMATTED_SUM_WITH_CURRENCY' => CCrmCurrency::MoneyToString($sum, $currencyID, '')));
}
$type = isset($_POST['OWNER_TYPE']) ? strtoupper($_POST['OWNER_TYPE']) : '';
if ($type !== 'I') {
    __CrmInvoiceShowEndJsonResonse(array('ERROR' => 'OWNER_TYPE IS NOT SUPPORTED!'));
}
if ($mode === 'UPDATE') {
    $ID = isset($_POST['OWNER_ID']) ? $_POST['OWNER_ID'] : 0;
    if ($ID <= 0) {
        __CrmInvoiceShowEndJsonResonse(array('ERROR' => 'ID IS INVALID OR NOT DEFINED!'));
    }
    $CCrmInvoice = new CCrmInvoice();
    if ($CCrmInvoice->cPerms->HavePerm('INVOICE', BX_CRM_PERM_NONE, 'WRITE') || !CCrmInvoice::CheckUpdatePermission($ID)) {
        __CrmInvoiceShowEndJsonResonse(array('ERROR' => 'PERMISSION DENIED!'));
    }
    $fieldNames = array();
    if (isset($_POST['FIELD_NAME'])) {
        if (is_array($_POST['FIELD_NAME'])) {
            $fieldNames = $_POST['FIELD_NAME'];
        } else {
            $fieldNames[] = $_POST['FIELD_NAME'];
        }
    }
    if (count($fieldNames) == 0) {
        __CrmInvoiceShowEndJsonResonse(array('ERROR' => 'FIELD_NAME IS NOT DEFINED!'));
    }
    $fieldValues = array();
    if (isset($_POST['FIELD_VALUE'])) {
Esempio n. 6
0
                     }
                     if ($errMsg == '') {
                         $errMsg = $ex->GetString();
                     }
                 }
                 $arResult['ERROR_MESSAGE'] = (!empty($errMsg) ? $errMsg : GetMessage('UNKNOWN_ERROR')) . "<br />\n";
                 unset($errCode, $errMsg);
             }
         }
         $ID = isset($arResult['ELEMENT']['ID']) ? $arResult['ELEMENT']['ID'] : 0;
         if (!empty($arResult['ERROR_MESSAGE'])) {
             ShowError($arResult['ERROR_MESSAGE']);
             $arResult['ELEMENT'] = CCrmComponentHelper::PrepareEntityFields(array_merge(array('ID' => $ID), $arFields), array('ORDER_TOPIC' => array('TYPE' => 'string'), 'STATUS_ID' => array('TYPE' => 'int'), 'DATE_INSERT' => array('TYPE' => 'datetime'), 'DATE_BILL' => array('TYPE' => 'date'), 'DATE_PAY_BEFORE' => array('TYPE' => 'date'), 'RESPONSIBLE_ID' => array('TYPE' => 'int'), 'COMMENTS' => array('TYPE' => 'string'), 'USER_DESCRIPTION' => array('TYPE' => 'string'), 'ACCOUNT_NUMBER' => array('TYPE' => 'string'), 'UF_QUOTE_ID' => array('TYPE' => 'int'), 'UF_DEAL_ID' => array('TYPE' => 'int'), 'UF_COMPANY_ID' => array('TYPE' => 'int'), 'UF_CONTACT_ID' => array('TYPE' => 'int'), 'PAY_VOUCHER_NUM' => array('TYPE' => 'string'), 'PAY_VOUCHER_DATE' => array('TYPE' => 'datetime'), 'REASON_MARKED' => array('TYPE' => 'string'), 'DATE_MARKED' => array('TYPE' => 'datetime')));
         } else {
             if (isset($_POST['apply'])) {
                 if (CCrmInvoice::CheckUpdatePermission($ID)) {
                     LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_INVOICE_EDIT'], array('invoice_id' => $ID)));
                 }
             } elseif (isset($_POST['saveAndAdd'])) {
                 LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_INVOICE_EDIT'], array('invoice_id' => 0)));
             } elseif (isset($_POST['saveAndView'])) {
                 if (CCrmInvoice::CheckReadPermission($ID)) {
                     LocalRedirect(empty($arResult['INVOICE_REFERER']) ? CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_INVOICE_SHOW'], array('invoice_id' => $ID)) : $arResult['INVOICE_REFERER']);
                 }
             }
             // save
             LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_INVOICE_LIST'], array()));
         }
     }
 } elseif (isset($_GET['delete']) && check_bitrix_sessid()) {
     if ($bEdit) {
 public static function delete($params)
 {
     global $DB;
     $ID = CCrmInvoiceRestUtil::getParamScalar($params, 'id', 0);
     if ($ID <= 0) {
         throw new RestException('Invalid identifier.');
     }
     $invoice = new CCrmInvoice();
     if (!CCrmInvoice::CheckUpdatePermission($ID)) {
         throw new RestException('Access denied.');
     }
     $DB->StartTransaction();
     if (!$invoice->Delete($ID)) {
         $DB->Rollback();
         throw new RestException('Error on deleting invoice.');
     } else {
         $DB->Commit();
     }
     return $ID;
 }