Exemple #1
9
 public static function GetDocumentType($documentId)
 {
     $arDocumentID = self::GetDocumentInfo($documentId);
     if (empty($arDocumentID)) {
         throw new CBPArgumentNullException('documentId');
     }
     switch ($arDocumentID['TYPE']) {
         case 'CONTACT':
             $dbDocumentList = CCrmContact::GetList(array(), array('ID' => $arDocumentID['ID'], "CHECK_PERMISSIONS" => "N"), array('ID'));
             break;
         case 'COMPANY':
             $dbDocumentList = CCrmCompany::GetList(array(), array('ID' => $arDocumentID['ID'], "CHECK_PERMISSIONS" => "N"), array('ID'));
             break;
         case 'DEAL':
             $dbDocumentList = CCrmDeal::GetList(array(), array('ID' => $arDocumentID['ID'], "CHECK_PERMISSIONS" => "N"), array('ID'));
             break;
         case 'LEAD':
             $dbDocumentList = CCrmLead::GetList(array(), array('ID' => $arDocumentID['ID'], "CHECK_PERMISSIONS" => "N"), array('ID'));
             break;
     }
     $arResult = $dbDocumentList->Fetch();
     if (!$arResult) {
         throw new Exception(GetMessage('CRM_DOCUMENT_ELEMENT_IS_NOT_FOUND'));
     }
     return $arDocumentID['TYPE'];
 }
Exemple #2
1
    $arDeal['PATH_TO_DEAL_EDIT'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_DEAL_EDIT'], array('deal_id' => $iDealId));
    $arDeal['PATH_TO_CONTACT_SHOW'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_SHOW'], array('contact_id' => $arDeal['CONTACT_ID']));
    $arDeal['PATH_TO_COMPANY_SHOW'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_COMPANY_SHOW'], array('company_id' => $arDeal['COMPANY_ID']));
    $arDeal['CONTACT_NAME'] = CUser::FormatName(\Bitrix\Crm\Format\PersonNameFormatter::getFormat(), array('NAME' => $arDeal['NAME'], 'LAST_NAME' => $arDeal['LAST_NAME'], 'SECOND_NAME' => $arDeal['SECOND_NAME']), true, false);
    $strCard = '
<div class="bx-user-info-data-cont-video bx-user-info-fields" id="bx_user_info_data_cont_1">
	<div class="bx-user-info-data-name">
		<a href="' . $arDeal['PATH_TO_DEAL_SHOW'] . '">' . htmlspecialcharsbx($arDeal['TITLE']) . '</a>
	</div>
	<div class="bx-user-info-data-info">';
    if (!empty($arDeal['STAGE_ID'])) {
        $strCard .= '<span class="field-name">' . GetMessage('CRM_COLUMN_STAGE_ID') . '</span>:
		<span class="fields enumeration">' . $arResult['STAGE_LIST'][$arDeal['STAGE_ID']] . '</span>
		<br />';
    }
    $arProductRows = CCrmDeal::LoadProductRows($arDeal['ID']);
    if (count($arProductRows) > 0) {
        $strCard .= '<span class="field-name">' . GetMessage('CRM_COLUMN_PRODUCTS') . '</span>:<span class="fields enumeration">' . htmlspecialcharsbx(CCrmProductRow::RowsToString($arProductRows)) . '</span><br />';
    }
    if (!empty($arDeal['OPPORTUNITY'])) {
        $strCard .= '<span class="field-name">' . GetMessage('CRM_COLUMN_OPPORTUNITY') . '</span>:
		<span class="fields enumeration"><nobr>' . number_format($arDeal['OPPORTUNITY'], 2, ',', ' ') . ' ' . htmlspecialcharsbx(CCrmCurrency::GetCurrencyName($arDeal['CURRENCY_ID'])) . '</nobr></span>
		<br />';
    }
    if (!empty($arDeal['PROBABILITY'])) {
        $strCard .= '<span class="field-name">' . GetMessage('CRM_COLUMN_PROBABILITY') . '</span>:
		<span class="fields enumeration">' . intval($arDeal['PROBABILITY']) . '%</span>
		<br />';
    }
    $strCard .= '<span class="field-name">' . GetMessage('CRM_COLUMN_DATE_MODIFY') . '</span>:
		<span class="fields enumeration">' . FormatDate('x', MakeTimeStamp($arDeal['DATE_MODIFY']), time() + CTimeZone::GetOffset()) . '</span>
 /**
  * @return array
  */
 public function prepareData()
 {
     $totals = array();
     $stages = \CCrmStatus::GetStatusList('DEAL_STAGE');
     foreach ($stages as $k => $v) {
         $semanticID = \CCrmDeal::GetSemanticID($k);
         if ($semanticID === PhaseSemantics::FAILURE) {
             continue;
         }
         $totals[$k] = array('ID' => $k, 'NAME' => $v, 'TOTAL' => 0);
     }
     $source = new DealStageHistory(array(), $this->userID, $this->enablePermissionCheck);
     //CREATION
     $this->filter->setExtras(array('typeID' => HistoryEntryType::CREATION));
     $values = $source->getList(array('filter' => $this->filter));
     $this->prepareTotals($values, $totals);
     //MODIFICATION
     $this->filter->setExtras(array('typeID' => HistoryEntryType::MODIFICATION));
     $values = $source->getList(array('filter' => $this->filter));
     $this->prepareTotals($values, $totals);
     //FINALIZATION
     $this->filter->setExtras(array('typeID' => HistoryEntryType::FINALIZATION));
     $values = $source->getList(array('filter' => $this->filter));
     $this->prepareTotals($values, $totals);
     $items = array();
     foreach ($totals as $total) {
         if ($total['TOTAL'] > 0) {
             $items[] = $total;
         }
     }
     return array('items' => $items, 'valueField' => 'TOTAL', 'titleField' => 'NAME');
 }
 /**
  * @return array Array of strings
  */
 public static function getJavaScriptDescriptions($checkPermissions = false)
 {
     $result = array();
     $descriptions = self::getAllDescriptions();
     if (!$checkPermissions) {
         $isInvoicePermitted = true;
         $isQuotePermitted = true;
     } else {
         $flags = array();
         \CCrmDeal::PrepareConversionPermissionFlags(0, $flags);
         $isInvoicePermitted = $flags['CAN_CONVERT_TO_INVOICE'];
         $isQuotePermitted = $flags['CAN_CONVERT_TO_QUOTE'];
     }
     if ($isInvoicePermitted && $isQuotePermitted) {
         foreach ($descriptions as $schemeID => $description) {
             $result[self::resolveName($schemeID)] = $description;
         }
     } else {
         $schemes = array();
         if ($isInvoicePermitted) {
             $schemes[] = self::INVOICE;
         }
         if ($isQuotePermitted) {
             $schemes[] = self::QUOTE;
         }
         foreach ($schemes as $schemeID) {
             $result[self::resolveName($schemeID)] = $descriptions[$schemeID];
         }
     }
     return $result;
 }
 protected function rebind($seedID, $targID)
 {
     \CCrmDeal::Rebind(\CCrmOwnerType::Contact, $seedID, $targID);
     \CCrmQuote::Rebind(\CCrmOwnerType::Contact, $seedID, $targID);
     \CCrmActivity::Rebind(\CCrmOwnerType::Contact, $seedID, $targID);
     \CCrmLiveFeed::Rebind(\CCrmOwnerType::Contact, $seedID, $targID);
     \CCrmSonetRelation::RebindRelations(\CCrmOwnerType::Contact, $seedID, $targID);
     \CCrmEvent::Rebind(\CCrmOwnerType::Contact, $seedID, $targID);
 }
 public function initialize()
 {
     if ($this->currentPhase === DealConversionPhase::INTERMEDIATE) {
         $this->currentPhase = DealConversionPhase::INVOICE_CREATION;
     }
     if (!\CCrmDeal::Exists($this->entityID)) {
         throw new EntityConversionException(\CCrmOwnerType::Deal, \CCrmOwnerType::Undefined, EntityConversionException::TARG_SRC, EntityConversionException::NOT_FOUND);
     }
     /** @var \CCrmPerms $permissions */
     $permissions = $this->getUserPermissions();
     if (!\CCrmAuthorizationHelper::CheckReadPermission(\CCrmOwnerType::DealName, $this->entityID, $permissions)) {
         throw new EntityConversionException(\CCrmOwnerType::Deal, \CCrmOwnerType::Undefined, EntityConversionException::TARG_SRC, EntityConversionException::READ_DENIED);
     }
     if (!\CCrmAuthorizationHelper::CheckUpdatePermission(\CCrmOwnerType::DealName, $this->entityID, $permissions)) {
         throw new EntityConversionException(\CCrmOwnerType::Deal, \CCrmOwnerType::Undefined, EntityConversionException::TARG_SRC, EntityConversionException::UPDATE_DENIED);
     }
 }
 private static function ResolveEntityInfo($typeID, $ID)
 {
     $typeID = intval($typeID);
     $ID = intval($ID);
     if (!(CCrmOwnerType::IsDefined($typeID) && $ID > 0)) {
         return array('TYPE_ID' => $typeID, 'TYPE_NAME' => CCrmOwnerType::ResolveName($typeID), 'ID' => $ID);
     }
     $fields = null;
     if ($typeID === CCrmOwnerType::Lead) {
         $fields = CCrmLead::GetByID($ID, false);
     } elseif ($typeID === CCrmOwnerType::Contact) {
         $fields = CCrmContact::GetByID($ID, false);
     } elseif ($typeID === CCrmOwnerType::Company) {
         $fields = CCrmCompany::GetByID($ID, false);
     } elseif ($typeID === CCrmOwnerType::Deal) {
         $fields = CCrmDeal::GetByID($ID, false);
     }
     return array('TYPE_ID' => $typeID, 'TYPE_NAME' => CCrmOwnerType::ResolveName($typeID), 'ID' => $ID, 'FIELDS' => $fields);
 }
Exemple #8
0
 public static function GetDealCostOriginal($deal_id)
 {
     $res = 0;
     $ar = CCrmDeal::GetByID($deal_id);
     if (is_array($ar)) {
         $res = $ar['OPPORTUNITY'];
     }
     return $res;
 }
 public static function synchronize($ownerID, array $entityFields = null)
 {
     if (!is_int($ownerID)) {
         $ownerID = (int) $ownerID;
     }
     if ($ownerID <= 0) {
         throw new Main\ArgumentException('Owner ID must be greater than zero.', 'ownerID');
     }
     $query = new Query(DealStageHistoryTable::getEntity());
     $query->addSelect('START_DATE');
     $query->addSelect('END_DATE');
     $query->addSelect('RESPONSIBLE_ID');
     $query->addFilter('=OWNER_ID', $ownerID);
     $query->setLimit(1);
     $dbResult = $query->exec();
     $first = $dbResult->fetch();
     if (!is_array($first)) {
         return false;
     }
     if (!is_array($entityFields)) {
         $dbResult = \CCrmDeal::GetListEx(array(), array('=ID' => $ownerID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ASSIGNED_BY_ID', 'BEGINDATE', 'CLOSEDATE'));
         $entityFields = is_object($dbResult) ? $dbResult->Fetch() : null;
         if (!is_array($entityFields)) {
             return false;
         }
     }
     $responsibleID = isset($entityFields['ASSIGNED_BY_ID']) ? (int) $entityFields['ASSIGNED_BY_ID'] : 0;
     $beginDate = isset($entityFields['BEGINDATE']) ? $entityFields['BEGINDATE'] : '';
     /** @var Date $startDate */
     $startDate = new Date($beginDate);
     $closeDate = isset($entityFields['CLOSEDATE']) ? $entityFields['CLOSEDATE'] : '';
     /** @var Date $endDate */
     $endDate = $closeDate !== '' ? new Date($closeDate) : new Date('9999-12-31', 'Y-m-d');
     if ($startDate->getTimestamp() === $first['START_DATE']->getTimestamp() && $endDate->getTimestamp() === $first['END_DATE']->getTimestamp() && $responsibleID === (int) $first['RESPONSIBLE_ID']) {
         return false;
     }
     DealStageHistoryTable::synchronize($ownerID, array('START_DATE' => $startDate, 'END_DATE' => $endDate, 'RESPONSIBLE_ID' => $responsibleID));
     return true;
 }
 public function map(EntityConversionMap $map, array $options = null)
 {
     $srcFields = $this->getSourceFields();
     if (empty($srcFields)) {
         return array();
     }
     $dstFields = array();
     $dstEntityTypeID = $map->getDestinationEntityTypeID();
     foreach ($map->getItems() as $item) {
         $dstFieldID = $item->getDestinationField();
         //Skip empty binding
         if ($dstFieldID === '-') {
             continue;
         }
         $srcFieldID = $item->getSourceField();
         if ((!isset($srcFields[$srcFieldID]) || $srcFields[$srcFieldID] === '') && $srcFieldID !== 'PRODUCT_ROWS') {
             $altSrcFieldID = '';
             foreach ($item->getAlternativeSourceFields() as $fieldID) {
                 if (isset($srcFields[$fieldID])) {
                     $altSrcFieldID = $fieldID;
                     break;
                 }
             }
             if ($altSrcFieldID !== '') {
                 $srcFieldID = $altSrcFieldID;
             }
         }
         if ($dstFieldID === '') {
             $dstFieldID = $srcFieldID;
         }
         if (strpos($srcFieldID, 'UF_') === 0 && strpos($dstFieldID, 'UF_') === 0) {
             self::mapUserField(\CCrmOwnerType::Deal, $srcFieldID, $srcFields, $dstEntityTypeID, $dstFieldID, $dstFields, $options);
         } elseif ($srcFieldID === 'PRODUCT_ROWS') {
             $productRows = \CCrmDeal::LoadProductRows($this->srcEntityID);
             if (count($productRows) > 0) {
                 if ($dstEntityTypeID === \CCrmOwnerType::Invoice) {
                     $currencyID = isset($srcFields['CURRENCY_ID']) ? $srcFields['CURRENCY_ID'] : '';
                     if ($currencyID === '' || !\CCrmCurrency::IsExists($currencyID)) {
                         $currencyID = \CCrmCurrency::GetBaseCurrencyID();
                     }
                     $actualRows = \CCrmInvoice::ProductRows2BasketItems($productRows, $currencyID, \CCrmInvoice::GetCurrencyID());
                     if (count($actualRows) > 0) {
                         foreach ($actualRows as &$productRow) {
                             unset($productRow['ID']);
                         }
                         unset($productRow);
                         $dstFields[$dstFieldID] = $actualRows;
                     }
                 } else {
                     foreach ($productRows as &$productRow) {
                         unset($productRow['ID']);
                     }
                     unset($productRow);
                     $dstFields[$dstFieldID] = $productRows;
                 }
             }
         } elseif (isset($srcFields[$srcFieldID])) {
             $dstFields[$dstFieldID] = $srcFields[$srcFieldID];
         }
     }
     if (!empty($dstFields)) {
         if ($dstEntityTypeID === \CCrmOwnerType::Invoice) {
             $dstFields['UF_DEAL_ID'] = $this->srcEntityID;
             //region Prepare Invoice Properties
             $dstFields['INVOICE_PROPERTIES'] = array();
             $invoiceEntity = new \CCrmInvoice(false);
             $companyID = isset($dstFields['UF_COMPANY_ID']) ? (int) $dstFields['UF_COMPANY_ID'] : 0;
             $contactID = isset($dstFields['UF_CONTACT_ID']) ? (int) $dstFields['UF_CONTACT_ID'] : 0;
             $personTypeID = 0;
             $personTypes = \CCrmPaySystem::getPersonTypeIDs();
             if ($companyID > 0 && isset($personTypes['COMPANY'])) {
                 $personTypeID = $personTypes['COMPANY'];
             } elseif (isset($personTypes['CONTACT'])) {
                 $personTypeID = $personTypes['CONTACT'];
             }
             $properties = $invoiceEntity->GetProperties(0, $personTypeID);
             if (is_array($properties)) {
                 \CCrmInvoice::__RewritePayerInfo($companyID, $contactID, $invoiceProperties);
                 foreach ($properties as $property) {
                     $dstFields['INVOICE_PROPERTIES'][$property['FIELDS']['ID']] = $property['VALUE'];
                 }
             }
             //endregion
         } elseif ($dstEntityTypeID === \CCrmOwnerType::Quote) {
             $dstFields['DEAL_ID'] = $this->srcEntityID;
         }
     }
     return $dstFields;
 }
Exemple #11
0
 public static function GetEntityList($entityTypeID, $userID, $sortOrder, array $filter, $navParams = false)
 {
     $entityTypeID = (int) $entityTypeID;
     $userID = (int) $userID;
     $userIDs = array(0);
     if ($userID > 0) {
         $userIDs[] = $userID;
     }
     $lb = null;
     if ($entityTypeID === CCrmOwnerType::Lead) {
         $lb = CCrmLead::CreateListBuilder();
     } else {
         if ($entityTypeID === CCrmOwnerType::Deal) {
             $lb = CCrmDeal::CreateListBuilder();
         } else {
             if ($entityTypeID === CCrmOwnerType::Contact) {
                 $lb = CCrmContact::CreateListBuilder();
             } else {
                 if ($entityTypeID === CCrmOwnerType::Company) {
                     $lb = CCrmCompany::CreateListBuilder();
                 }
             }
         }
     }
     if (!$lb) {
         return null;
     }
     $fields = $lb->GetFields();
     $entityAlias = $lb->GetTableAlias();
     $join = 'LEFT JOIN ' . CCrmActivity::USER_ACTIVITY_TABLE_NAME . ' UA ON UA.USER_ID IN (' . implode(',', $userIDs) . ') AND UA.OWNER_ID = ' . $entityAlias . '.ID AND UA.OWNER_TYPE_ID = ' . $entityTypeID;
     $fields['ACTIVITY_USER_ID'] = array('FIELD' => 'MAX(UA.USER_ID)', 'TYPE' => 'int', 'FROM' => $join);
     $fields['ACTIVITY_SORT'] = array('FIELD' => 'MAX(UA.SORT)', 'TYPE' => 'string', 'FROM' => $join);
     $lb->SetFields($fields);
     $sortOrder = strtoupper($sortOrder);
     if ($sortOrder !== 'DESC' && $sortOrder !== 'ASC') {
         $sortOrder = 'ASC';
     }
     $options = array('PERMISSION_SQL_TYPE' => 'FROM', 'PERMISSION_SQL_UNION' => 'DISTINCT');
     return $lb->Prepare(array('ACTIVITY_USER_ID' => 'DESC', 'ACTIVITY_SORT' => $sortOrder, 'ID' => $sortOrder), $filter, array('ID'), $navParams, array('ID'), $options);
 }
Exemple #12
0
}
$entityTypeName = CCrmOwnerType::ResolveName($entityTypeID);
$userPerms = CCrmPerms::GetCurrentUserPermissions();
if (!CCrmAuthorizationHelper::CheckReadPermission($entityTypeName, $entityID, $userPerms)) {
    ShowError(GetMessage('CRM_PERMISSION_DENIED'));
    return;
}
$arParams['UID'] = isset($arParams['UID']) ? $arParams['UID'] : '';
if (!isset($arParams['UID']) || $arParams['UID'] === '') {
    $arParams['UID'] = 'mobile_crm_product_row_list';
}
$arResult['UID'] = $arParams['UID'];
$arResult['ITEMS'] = array();
$arResult['TAX_MODE'] = 'NONE';
if ($entityTypeID === CCrmOwnerType::Deal) {
    $dbRes = CCrmDeal::GetListEx(array(), array('ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('TITLE', 'CURRENCY_ID', 'OPPORTUNITY'));
    $arOwner = $dbRes ? $dbRes->Fetch() : null;
    if ($arOwner) {
        $arResult['TITLE'] = isset($arOwner['TITLE']) ? $arOwner['TITLE'] : '';
        $arResult['CURRENCY_ID'] = isset($arOwner['CURRENCY_ID']) ? $arOwner['CURRENCY_ID'] : CCrmCurrency::GetBaseCurrencyID();
        $arResult['SUM'] = isset($arOwner['OPPORTUNITY']) ? $arOwner['OPPORTUNITY'] : 0.0;
    } else {
        $arResult['TITLE'] = '';
        $arResult['CURRENCY_ID'] = CCrmCurrency::GetBaseCurrencyID();
        $arResult['SUM'] = 0.0;
    }
    $productRows = CCrmProductRow::LoadRows(CCrmOwnerTypeAbbr::Deal, $entityID);
    foreach ($productRows as &$productRow) {
        $productRow['FORMATTED_PRICE'] = CCrmCurrency::MoneyToString($productRow['PRICE'], $arResult['CURRENCY_ID']);
        $arResult['ITEMS'][] = $productRow;
    }
Exemple #13
0
 }
 // Add Contact
 require_once "contact.demo.php";
 $CCrmContact = new CCrmContact();
 foreach ($arContacts as $ID => $arParams) {
     $arContacts[$ID]['ID'] = $CCrmContact->Add($arParams);
 }
 // Add Company
 require_once "company.demo.php";
 $CCrmCompany = new CCrmCompany();
 foreach ($arCompany as $ID => $arParams) {
     $arCompany[$ID]['ID'] = $CCrmCompany->Add($arParams);
 }
 // Add Deal
 require_once "deal.demo.php";
 $CCrmDeal = new CCrmDeal();
 foreach ($arDeals as $ID => &$arParams) {
     $arProductRows = null;
     if (isset($arParams['PRODUCT_ROWS'])) {
         $arProductRows = $arParams['PRODUCT_ROWS'];
         unset($arParams['PRODUCT_ROWS']);
     }
     $arParams['CURRENCY_ID'] = $currencyID;
     $dealID = $CCrmDeal->Add($arParams);
     $arDeals[$ID]['ID'] = $dealID;
     if (is_array($arProductRows)) {
         foreach ($arProductRows as &$arProductRow) {
             $originID = $arProductRow['ORIGIN_ID'];
             $arProduct = CCrmProduct::GetByOriginID($originID, $catalogID);
             if (!is_array($arProduct)) {
                 continue;
Exemple #14
0
// page count
$arResult['PAGER_PARAM'] = "PAGEN_{$arResult['PAGE_NAVNUM']}";
$arResult['PAGE_NEXT_NUMBER'] = $arResult['PAGE_NUMBER'] + 1;
while ($item = $dbRes->Fetch()) {
    $itemID = intval($item['ID']);
    $ownerID = intval($item['OWNER_ID']);
    $ownerTypeID = intval($item['OWNER_TYPE_ID']);
    CCrmMobileHelper::PrepareActivityItem($item, $arParams, array('ENABLE_COMMUNICATIONS' => false));
    $arResult['ITEMS'][] =& $item;
    unset($item);
}
if ($arResult['PAGE_NEXT_NUMBER'] > $arResult['PAGE_NAVCOUNT']) {
    $arResult['NEXT_PAGE_URL'] = '';
} else {
    $arResult['NEXT_PAGE_URL'] = $APPLICATION->GetCurPageParam('AJAX_CALL=Y&PAGING=Y&FORMAT=json&' . $arResult['PAGER_PARAM'] . '=' . $arResult['PAGE_NEXT_NUMBER'], array('AJAX_CALL', 'PAGING', 'FORMAT', 'SEARCH', $arResult['PAGER_PARAM']));
}
$arResult['SEARCH_PAGE_URL'] = $APPLICATION->GetCurPageParam('AJAX_CALL=Y&SEARCH=Y&FORMAT=json&apply_filter=Y&save=Y', array('AJAX_CALL', 'SEARCH', 'FORMAT', 'save', 'apply_filter', 'clear_filter'));
$arResult['SERVICE_URL'] = SITE_DIR . 'bitrix/components/bitrix/mobile.crm.activity.list/ajax.php?siteID=' . SITE_ID . '&' . bitrix_sessid_get();
$arResult['IS_FILTERED'] = !empty($filter);
$arResult['CREATE_CALL_URL'] = $arParams['ACTIVITY_CREATE_URL_TEMPLATE'] !== '' ? CComponentEngine::makePathFromTemplate($arParams['ACTIVITY_CREATE_URL_TEMPLATE'], array('owner_type' => $entityTypeName, 'owner_id' => $entityID, 'type_id' => CCrmActivityType::Call)) : '';
$arResult['CREATE_MEETING_URL'] = $arParams['ACTIVITY_CREATE_URL_TEMPLATE'] !== '' ? CComponentEngine::makePathFromTemplate($arParams['ACTIVITY_CREATE_URL_TEMPLATE'], array('owner_type' => $entityTypeName, 'owner_id' => $entityID, 'type_id' => CCrmActivityType::Meeting)) : '';
$arResult['CREATE_EMAIL_URL'] = $arParams['ACTIVITY_CREATE_URL_TEMPLATE'] !== '' ? CComponentEngine::makePathFromTemplate($arParams['ACTIVITY_CREATE_URL_TEMPLATE'], array('owner_type' => $entityTypeName, 'owner_id' => $entityID, 'type_id' => CCrmActivityType::Email)) : '';
$arResult['RELOAD_URL'] = $APPLICATION->GetCurPageParam('AJAX_CALL=Y&FORMAT=json', array('AJAX_CALL', 'SEARCH', 'FORMAT', 'save', 'apply_filter', 'clear_filter'));
//Require any update permission
$arResult['PERMISSIONS'] = array('CREATE' => CCrmLead::CheckUpdatePermission(0, $userPerms) || CCrmCompany::CheckUpdatePermission(0, $userPerms) || CCrmContact::CheckUpdatePermission(0, $userPerms) || CCrmDeal::CheckUpdatePermission(0, $userPerms));
$format = isset($_REQUEST['FORMAT']) ? strtolower($_REQUEST['FORMAT']) : '';
// Only JSON format is supported
if ($format !== '' && $format !== 'json') {
    $format = '';
}
$this->IncludeComponentTemplate($format);
Exemple #15
0
                 continue;
             }
             $productID = isset($arProduct['ID']) ? $arProduct['ID'] : 0;
             if ($productID <= 0) {
                 continue;
             }
             $arProductRows = array(array('PRODUCT_ID' => $productID, 'PRICE' => isset($arLead['OPPORTUNITY']) ? doubleval($arLead['OPPORTUNITY']) : 0.0, 'QUANTITY' => 1));
             CCrmLead::SaveProductRows($ID, $arProductRows);
         }
     }
     COption::SetOptionString('crm', '~crm_11_0_6_convertion', 'Y');
 }
 // <-- Convert LEAD CURRENCY and PRODUCT
 // Convert DEAL EVENTS -->
 if (COption::GetOptionString('crm', '~CRM_DEAL_EVENT_CONVERT_11_5_7', 'N') !== 'Y') {
     $dbDeals = CCrmDeal::GetListEx(array(), array('@EVENT_ID' => array('PHONE', 'INFO')), false, false, array());
     while ($arDeal = $dbDeals->Fetch()) {
         CCrmActivity::CreateFromDealEvent($arDeal);
     }
     COption::SetOptionString('crm', '~CRM_DEAL_EVENT_CONVERT_11_5_7', 'Y');
 }
 // <-- Convert DEAL EVENTS
 // SETUP DEFAULT RESPONSIBLE FOR COMPANIES-->
 if (COption::GetOptionString('crm', '~CRM_COMPANY_RESPONSIBLE_11_5_7', 'N') !== 'Y') {
     try {
         if (CCrmCompany::SetDefaultResponsible(true)) {
             COption::SetOptionString('crm', '~CRM_COMPANY_RESPONSIBLE_11_5_7', 'Y');
         }
     } catch (Exception $e) {
     }
 }
Exemple #16
0
        } elseif ($k === 'COMPANY_ID') {
            $entityData['COMPANY_ID'] = __CrmQuickPanelViewPrepareClientInfo(CCrmOwnerType::CompanyName, $entityContext);
        } elseif ($k === 'CONTACT_ID') {
            $entityData['CONTACT_ID'] = __CrmQuickPanelViewPrepareClientInfo(CCrmOwnerType::ContactName, $entityContext);
        } elseif ($k === 'ASSIGNED_BY_ID') {
            $entityData['ASSIGNED_BY_ID'] = __CrmQuickPanelViewPrepareResponsible($entityFields, $userProfilePath, $nameTemplate, $enableInstantEdit, $arResult['INSTANT_EDITOR_ID'], $arResult['SERVICE_URL']);
        } elseif ($k === 'PROBABILITY') {
            $entityData[$k] = array('type' => 'text', 'editable' => $enableInstantEdit, 'data' => array('baseType' => 'int', 'text' => $entityFields["~{$k}"]));
        } elseif ($k === 'COMMENTS') {
            $entityData[$k] = array('type' => 'html', 'editable' => $enableInstantEdit, 'data' => array('html' => $entityFields["~{$k}"], 'serviceUrl' => $arResult['SERVICE_URL']));
        } else {
            $entityData[$k] = array('type' => 'text', 'editable' => $enableInstantEdit, 'data' => array('text' => $entityFields["~{$k}"]));
        }
        $caption = isset($formFieldNames[$k]) ? $formFieldNames[$k] : '';
        if ($caption === '') {
            $caption = CCrmDeal::GetFieldCaption($k);
        }
        $entityData[$k]['caption'] = $caption;
    }
    $arResult['HEAD_TITLE'] = isset($entityFields['TITLE']) ? $entityFields['TITLE'] : '';
    $arResult['HEAD_TITLE_FIELD_ID'] = 'TITLE';
} elseif ($entityTypeID === CCrmOwnerType::Lead) {
    $entityContext['SIP_MANAGER_CONFIG'][CCrmOwnerType::LeadName] = array('ENTITY_TYPE' => CCrmOwnerType::LeadName, 'SERVICE_URL' => '/bitrix/components/bitrix/crm.lead.show/ajax.php?' . bitrix_sessid_get());
    $ufEntityID = CCrmLead::$sUFEntityID;
    $fieldKeys = array('TITLE' => true, 'COMPANY_TITLE' => true, 'NAME' => true, 'SECOND_NAME' => true, 'LAST_NAME' => true, 'STATUS_ID' => true, 'STATUS_DESCRIPTION' => true, 'SOURCE_ID' => true, 'SOURCE_DESCRIPTION' => true, 'CURRENCY_ID' => true, 'OPPORTUNITY' => true, 'POST' => true, 'ADDRESS' => true, 'BIRTHDATE' => true, 'OPENED' => true, 'ASSIGNED_BY_ID' => true, 'COMMENTS' => true);
    if ($enableDefaultConfig) {
        $config['left'] = 'SOURCE_ID,SOURCE_DESCRIPTION';
        $config['center'] = 'PHONE,EMAIL,IM';
        $config['right'] = 'ASSIGNED_BY_ID';
        $config['bottom'] = 'COMMENTS';
    }
Exemple #17
0
 public static function SetAccountCurrencyID($currencyID)
 {
     $currencyID = self::NormalizeCurrencyID($currencyID);
     if ($currencyID === self::$ACCOUNT_CURRENCY_ID) {
         return;
     }
     self::$ACCOUNT_CURRENCY_ID = $currencyID;
     COption::SetOptionString('crm', 'account_currency_id', self::$ACCOUNT_CURRENCY_ID);
     CCrmDeal::OnAccountCurrencyChange();
     CCrmLead::OnAccountCurrencyChange();
 }
 /**
  * @return boolean
  */
 public static function synchronize($ownerID, array $entityFields = null)
 {
     if (!is_int($ownerID)) {
         $ownerID = (int) $ownerID;
     }
     if ($ownerID <= 0) {
         throw new Main\ArgumentException('Owner ID must be greater than zero.', 'ownerID');
     }
     $query = new Query(DealActivityStatisticsTable::getEntity());
     $query->addSelect('RESPONSIBLE_ID');
     $query->addFilter('=OWNER_ID', $ownerID);
     $query->setLimit(1);
     $dbResult = $query->exec();
     $first = $dbResult->fetch();
     if (!is_array($first)) {
         return false;
     }
     if (!is_array($entityFields)) {
         $dbResult = \CCrmDeal::GetListEx(array(), array('=ID' => $ownerID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ASSIGNED_BY_ID'));
         $entityFields = is_object($dbResult) ? $dbResult->Fetch() : null;
         if (!is_array($entityFields)) {
             return false;
         }
     }
     $responsibleID = isset($entityFields['ASSIGNED_BY_ID']) ? (int) $entityFields['ASSIGNED_BY_ID'] : 0;
     if ($responsibleID === (int) $first['RESPONSIBLE_ID']) {
         return false;
     }
     DealActivityStatisticsTable::synchronize($ownerID, array('RESPONSIBLE_ID' => $responsibleID));
     return true;
 }
Exemple #19
0
                $fieldName = $arMatch[1];
                if (($fieldName == 'DATE_CREATE' || $fieldName == 'DATE_MODIFY' || $fieldName == 'BEGINDATE' || $fieldName == 'CLOSEDATE') && !preg_match('/\\d{1,2}:\\d{1,2}(:\\d{1,2})?$/' . BX_UTF_PCRE_MODIFIER, $v)) {
                    $v .= ' 23:59:59';
                }
                $arFilter['<=' . $arMatch[1]] = $v;
            }
            unset($arFilter[$k]);
        } else {
            if (strpos($k, 'UF_') !== 0 && $k != 'LOGIC') {
                $arFilter['%' . $k] = $v;
                unset($arFilter[$k]);
            }
        }
    }
}
$obRes = CCrmDeal::GetListEx(array(), $arFilter, false, false, array('ID', 'TITLE', 'STAGE_ID', 'OPPORTUNITY', 'CURRENCY_ID'));
$arResult['DEAL'] = array();
$arResult['STAGE_COUNT'] = array();
$arResult['FUNNEL'] = array();
$iDealCount = 0;
while ($arDeal = $obRes->GetNext()) {
    //Normalizing for compatibility
    $currencyID = CCrmCurrency::NormalizeCurrencyID($arDeal['CURRENCY_ID']);
    $stageID = $arDeal['STAGE_ID'];
    $opportunity = (double) $arDeal['OPPORTUNITY'];
    if (!isset($arResult['STAGE_COUNT'][$stageID])) {
        $arResult['STAGE_COUNT'][$stageID]['COUNT'] = 1;
        $arResult['STAGE_COUNT'][$stageID]['COUNT_FUNNEL'] = 1;
        $arResult['STAGE_COUNT'][$stageID]['OPPORTUNITY'] = array($currencyID => $opportunity);
        $arResult['STAGE_COUNT'][$stageID]['OPPORTUNITY_FUNNEL'] = array($currencyID => $opportunity);
    } else {
Exemple #20
0
 public static function GetDocumentType($documentId)
 {
     $arDocumentID = self::GetDocumentInfo($documentId);
     if (empty($arDocumentID)) {
         throw new CBPArgumentNullException('documentId');
     }
     $exists = false;
     switch ($arDocumentID['TYPE']) {
         case 'CONTACT':
             $exists = CCrmContact::Exists($arDocumentID['ID']);
             break;
         case 'COMPANY':
             $exists = CCrmCompany::Exists($arDocumentID['ID']);
             break;
         case 'DEAL':
             $exists = CCrmDeal::Exists($arDocumentID['ID']);
             break;
         case 'LEAD':
             $exists = CCrmLead::Exists($arDocumentID['ID']);
             break;
     }
     if (!$exists) {
         throw new Exception(GetMessage('CRM_DOCUMENT_ELEMENT_IS_NOT_FOUND'));
     }
     return $arDocumentID['TYPE'];
 }
Exemple #21
0
         $arDesc = array();
         if (isset($arCompanyTypeList[$arRes['COMPANY_TYPE']])) {
             $arDesc[] = $arCompanyTypeList[$arRes['COMPANY_TYPE']];
         }
         if (isset($arCompanyIndustryList[$arRes['INDUSTRY']])) {
             $arDesc[] = $arCompanyIndustryList[$arRes['INDUSTRY']];
         }
         $ar[] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => implode(', ', $arDesc), 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_company_show'), array('company_id' => $arRes['ID'])), 'image' => $arImg['src'], 'type' => 'company', 'selected' => $sSelected);
     }
     $arResult['ELEMENT'] = array_merge($ar, $arResult['ELEMENT']);
 }
 if ($arSettings['DEAL'] == 'Y' && isset($arSelected['DEAL']) && !empty($arSelected['DEAL'])) {
     $arDealStageList = CCrmStatus::GetStatusListEx('DEAL_STAGE');
     $arSelect = array('ID', 'TITLE', 'STAGE_ID', 'COMPANY_TITLE', 'CONTACT_FULL_NAME');
     $ar = array();
     $obRes = CCrmDeal::GetList(array('ID' => 'DESC'), array('ID' => $arSelected['DEAL']), $arSelect);
     while ($arRes = $obRes->Fetch()) {
         $arRes['SID'] = $arResult['PREFIX'] == 'Y' ? 'D_' . $arRes['ID'] : $arRes['ID'];
         if (isset($arResult['SELECTED'][$arRes['SID']])) {
             unset($arResult['SELECTED'][$arRes['SID']]);
             $sSelected = 'Y';
         } else {
             $sSelected = 'N';
         }
         $clientTitle = !empty($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : '';
         $clientTitle .= ($clientTitle !== '' && !empty($arRes['CONTACT_FULL_NAME']) ? ', ' : '') . $arRes['CONTACT_FULL_NAME'];
         $ar[] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => $clientTitle, 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_show'), array('deal_id' => $arRes['ID'])), 'type' => 'deal', 'selected' => $sSelected);
     }
     $arResult['ELEMENT'] = array_merge($ar, $arResult['ELEMENT']);
 }
 if ($arSettings['QUOTE'] == 'Y' && isset($arSelected['QUOTE']) && !empty($arSelected['QUOTE'])) {
 public static function TryGetInfo($typeID, $ID, &$info, $bCheckPermissions = false)
 {
     $typeID = intval($typeID);
     $ID = intval($ID);
     if ($ID <= 0) {
         return array();
     }
     $result = null;
     switch ($typeID) {
         case self::Lead:
             $dbRes = CCrmLead::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $bCheckPermissions ? 'Y' : 'N'), false, false, array('TITLE'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             if (is_array($arRes)) {
                 $info = array('CAPTION' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '', 'IMAGE_ID' => 0);
                 return true;
             }
             break;
         case self::Contact:
             $dbRes = CCrmContact::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $bCheckPermissions ? 'Y' : 'N'), false, false, array('NAME', 'SECOND_NAME', 'LAST_NAME', 'PHOTO'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             if (is_array($arRes)) {
                 $info = array('CAPTION' => CUser::FormatName(\Bitrix\Crm\Format\PersonNameFormatter::getFormat(), array('LOGIN' => '', 'NAME' => isset($arRes['NAME']) ? $arRes['NAME'] : '', 'SECOND_NAME' => isset($arRes['SECOND_NAME']) ? $arRes['SECOND_NAME'] : '', 'LAST_NAME' => isset($arRes['LAST_NAME']) ? $arRes['LAST_NAME'] : ''), false, false), 'IMAGE_ID' => isset($arRes['PHOTO']) ? intval($arRes['PHOTO']) : 0);
                 return true;
             }
             break;
         case self::Company:
             $dbRes = CCrmCompany::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $bCheckPermissions ? 'Y' : 'N'), false, false, array('TITLE', 'LOGO'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             if (is_array($arRes)) {
                 $info = array('CAPTION' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '', 'IMAGE_ID' => isset($arRes['LOGO']) ? intval($arRes['LOGO']) : 0);
                 return true;
             }
             break;
         case self::Deal:
             $dbRes = CCrmDeal::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $bCheckPermissions ? 'Y' : 'N'), false, false, array('TITLE'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             if (is_array($arRes)) {
                 $info = array('CAPTION' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '', 'IMAGE_ID' => 0);
                 return true;
             }
             break;
         case self::Invoice:
             $dbRes = CCrmInvoice::GetList(array(), array('ID' => $ID), false, false, array('ORDER_TOPIC'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             if (is_array($arRes)) {
                 $info = array('CAPTION' => isset($arRes['ORDER_TOPIC']) ? $arRes['ORDER_TOPIC'] : '', 'IMAGE_ID' => 0);
                 return true;
             }
             break;
         case self::Quote:
             $dbRes = CCrmQuote::GetList(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $bCheckPermissions ? 'Y' : 'N'), false, false, array('TITLE'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             if (is_array($arRes)) {
                 $info = array('CAPTION' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '', 'IMAGE_ID' => 0);
                 return true;
             }
             break;
     }
     return false;
 }
Exemple #23
0
if (isset($arResult['ELEMENT']['CURRENCY_ID']) && $arResult['ELEMENT']['CURRENCY_ID'] !== '') {
    $currencyID = $arResult['ELEMENT']['CURRENCY_ID'];
}
$arResult['FIELDS']['tab_1'][] = array('id' => 'CURRENCY_ID', 'name' => GetMessage('CRM_QUOTE_FIELD_CURRENCY_ID'), 'type' => 'list', 'params' => array('sale_order_marker' => 'Y'), 'items' => $arResult['CURRENCY_LIST'], 'value' => $currencyID);
$arResult['FIELDS']['tab_1'][] = array('id' => 'OPPORTUNITY', 'name' => GetMessage('CRM_QUOTE_FIELD_OPPORTUNITY'), 'params' => array('size' => 21, 'sale_order_marker' => 'Y'), 'value' => isset($arResult['ELEMENT']['OPPORTUNITY']) ? $arResult['ELEMENT']['OPPORTUNITY'] : '', 'type' => 'text');
$arResult['RESPONSIBLE_SELECTOR_PARAMS'] = array('NAME' => 'crm_quote_edit_resonsible', 'INPUT_NAME' => 'ASSIGNED_BY_ID', 'SEARCH_INPUT_NAME' => 'ASSIGNED_BY_NAME', 'NAME_TEMPLATE' => $arParams['NAME_TEMPLATE']);
$arResult['FIELDS']['tab_1'][] = array('id' => 'ASSIGNED_BY_ID', 'componentParams' => $arResult['RESPONSIBLE_SELECTOR_PARAMS'], 'name' => GetMessage('CRM_QUOTE_FIELD_ASSIGNED_BY_ID'), 'type' => 'intranet_user_search', 'value' => isset($arResult['ELEMENT']['ASSIGNED_BY_ID']) ? $arResult['ELEMENT']['ASSIGNED_BY_ID'] : $USER->GetID());
//Fix for issue #36848
$beginDate = isset($arResult['ELEMENT']['BEGINDATE']) ? $arResult['ELEMENT']['BEGINDATE'] : '';
$closeDate = isset($arResult['ELEMENT']['CLOSEDATE']) ? $arResult['ELEMENT']['CLOSEDATE'] : '';
$arResult['FIELDS']['tab_1'][] = array('id' => 'BEGINDATE', 'name' => GetMessage('CRM_QUOTE_FIELD_BEGINDATE'), 'params' => array('sale_order_marker' => 'Y'), 'type' => 'date_link', 'value' => $beginDate !== '' ? ConvertTimeStamp(MakeTimeStamp($beginDate), 'SHORT', SITE_ID) : '');
$arResult['FIELDS']['tab_1'][] = array('id' => 'CLOSEDATE', 'name' => GetMessage('CRM_QUOTE_FIELD_CLOSEDATE'), 'type' => 'date_short', 'value' => $closeDate !== '' ? ConvertTimeStamp(MakeTimeStamp($closeDate), 'SHORT', SITE_ID) : '', 'params' => array('class' => 'bx-crm-dialog-input bx-crm-dialog-input-date'));
if (CCrmLead::CheckReadPermission()) {
    $arResult['FIELDS']['tab_1'][] = array('id' => 'LEAD_ID', 'name' => GetMessage('CRM_QUOTE_FIELD_LEAD_ID'), 'type' => 'crm_entity_selector', 'componentParams' => array('ENTITY_TYPE' => 'LEAD', 'INPUT_NAME' => 'LEAD_ID', 'NEW_INPUT_NAME' => '', 'INPUT_VALUE' => isset($arResult['ELEMENT']['LEAD_ID']) ? $arResult['ELEMENT']['LEAD_ID'] : '', 'FORM_NAME' => $arResult['FORM_ID'], 'MULTIPLE' => 'N', 'NAME_TEMPLATE' => \Bitrix\Crm\Format\PersonNameFormatter::getFormat()));
}
if (CCrmDeal::CheckReadPermission()) {
    $arResult['FIELDS']['tab_1'][] = array('id' => 'DEAL_ID', 'name' => GetMessage('CRM_QUOTE_FIELD_DEAL_ID'), 'type' => 'crm_entity_selector', 'componentParams' => array('ENTITY_TYPE' => 'DEAL', 'INPUT_NAME' => 'DEAL_ID', 'NEW_INPUT_NAME' => '', 'INPUT_VALUE' => isset($arResult['ELEMENT']['DEAL_ID']) ? $arResult['ELEMENT']['DEAL_ID'] : '', 'FORM_NAME' => $arResult['FORM_ID'], 'MULTIPLE' => 'N', 'NAME_TEMPLATE' => \Bitrix\Crm\Format\PersonNameFormatter::getFormat()));
}
$arResult['FIELDS']['tab_1'][] = array('id' => 'OPENED', 'name' => GetMessage('CRM_QUOTE_FIELD_OPENED'), 'type' => 'vertical_checkbox', 'params' => array(), 'value' => isset($arResult['ELEMENT']['OPENED']) ? $arResult['ELEMENT']['OPENED'] : true, 'title' => GetMessage('CRM_QUOTE_FIELD_OPENED_TITLE'));
$arResult['FIELDS']['tab_1'][] = array('id' => 'section_contact_info', 'name' => GetMessage('CRM_SECTION_CLIENT_INFO'), 'type' => 'section');
if (CCrmContact::CheckReadPermission()) {
    $arResult['FIELDS']['tab_1'][] = array('id' => 'CONTACT_ID', 'name' => GetMessage('CRM_QUOTE_FIELD_CONTACT_ID'), 'type' => 'crm_entity_selector', 'componentParams' => array('ENTITY_TYPE' => 'CONTACT', 'INPUT_NAME' => 'CONTACT_ID', 'NEW_INPUT_NAME' => CCrmContact::CheckCreatePermission() ? 'NEW_CONTACT_ID' : '', 'INPUT_VALUE' => isset($arResult['ELEMENT']['CONTACT_ID']) ? $arResult['ELEMENT']['CONTACT_ID'] : '', 'FORM_NAME' => $arResult['FORM_ID'], 'MULTIPLE' => 'N', 'NAME_TEMPLATE' => \Bitrix\Crm\Format\PersonNameFormatter::getFormat()));
}
if (CCrmCompany::CheckReadPermission()) {
    $arResult['FIELDS']['tab_1'][] = array('id' => 'COMPANY_ID', 'name' => GetMessage('CRM_QUOTE_FIELD_COMPANY_ID'), 'type' => 'crm_entity_selector', 'componentParams' => array('ENTITY_TYPE' => 'COMPANY', 'INPUT_NAME' => 'COMPANY_ID', 'NEW_INPUT_NAME' => CCrmCompany::CheckCreatePermission() ? 'NEW_COMPANY_ID' : '', 'INPUT_VALUE' => isset($arResult['ELEMENT']['COMPANY_ID']) ? $arResult['ELEMENT']['COMPANY_ID'] : '', 'FORM_NAME' => $arResult['FORM_ID'], 'MULTIPLE' => 'N', 'NAME_TEMPLATE' => \Bitrix\Crm\Format\PersonNameFormatter::getFormat()));
}
if ($bTaxMode) {
    // CLIENT LOCATION
    $sLocationHtml = '';
    $locValue = isset($arResult['ELEMENT']['LOCATION_ID']) ? $arResult['ELEMENT']['LOCATION_ID'] : '';
    ob_start();
 public static function beforeViewDataQuery(&$select, &$filter, &$group, &$order, &$limit, &$options, &$runtime)
 {
     // permission
     $addClause = CCrmDeal::BuildPermSql('crm_product_row_deal_owner');
     if ($addClause === false) {
         // access dinied
         $filter = array($filter, '=DEAL_OWNER.ID' => '0');
     } elseif (!empty($addClause)) {
         global $DB;
         // HACK: add escape chars for ORM
         $addClause = str_replace('crm_product_row_deal_owner.ID', $DB->escL . 'crm_product_row_deal_owner' . $DB->escR . '.ID', $addClause);
         $filter = array($filter, '=IS_ALLOWED' => '1');
         $runtime['IS_ALLOWED'] = array('data_type' => 'integer', 'expression' => array('CASE WHEN ' . $addClause . ' THEN 1 ELSE 0 END'));
         // Strongly required for permision check.
         if (!isset($select['CRM_PRODUCT_ROW_DEAL_OWNER_ID'])) {
             $select['CRM_PRODUCT_ROW_DEAL_OWNER_ID'] = 'DEAL_OWNER.ID';
         }
     }
     if (!isset($select['CRM_PRODUCT_ROW_IBLOCK_ELEMENT_ID'])) {
         $select['CRM_PRODUCT_ROW_IBLOCK_ELEMENT_ID'] = 'IBLOCK_ELEMENT.ID';
     }
     if (!isset($select['CRM_PRODUCT_ROW_IBLOCK_ELEMENT_IBLOCK_ID'])) {
         $select['CRM_PRODUCT_ROW_IBLOCK_ELEMENT_IBLOCK_ID'] = 'IBLOCK_ELEMENT.IBLOCK_ID';
     }
 }
Exemple #25
0
        __CrmMobileDealEditEndResonse(array('ERROR' => GetMessage('CRM_ENTITY_DATA_NOT_FOUND')));
    }
    $ID = isset($data['ID']) ? intval($data['ID']) : 0;
    if ($ID <= 0) {
        __CrmMobileDealEditEndResonse(array('ERROR' => GetMessage('CRM_ENTITY_ID_NOT_FOUND')));
    }
    if (!CCrmDeal::CheckUpdatePermission($ID, $curUserPrems)) {
        __CrmMobileDealEditEndResonse(array('ERROR' => GetMessage('CRM_ACCESS_DENIED')));
    }
    $stageID = isset($data['STAGE_ID']) ? $data['STAGE_ID'] : '';
    if ($stageID === '') {
        __CrmMobileDealEditEndResonse(array('ERROR' => GetMessage('CRM_DEAL_STAGE_NOT_FOUND')));
    }
    //$DB->StartTransaction();
    $fields = array('STAGE_ID' => $stageID);
    $entity = new CCrmDeal(false);
    $successed = $entity->Update($ID, $fields, true, true, array());
    if ($successed) {
        //$DB->Commit();
        $errors = array();
        CCrmBizProcHelper::AutoStartWorkflows(CCrmOwnerType::Deal, $ID, CCrmBizProcEventType::Edit, $errors);
        $dbRes = CCrmDeal::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N'));
        $currentItem = $dbRes->GetNext();
        $formatParams = isset($_REQUEST['FORMAT_PARAMS']) ? $_REQUEST['FORMAT_PARAMS'] : array();
        CCrmMobileHelper::PrepareDealItem($currentItem, $formatParams);
        __CrmMobileDealEditEndResonse(array('SAVED_ENTITY_ID' => $ID, 'SAVED_ENTITY_DATA' => CCrmMobileHelper::PrepareDealData($currentItem)));
    } else {
        //$DB->Rollback();
        __CrmMobileDealEditEndResonse(array('ERROR' => $fields['RESULT_MESSAGE']));
    }
} elseif ($action === 'CONVERT_MONEY') {
 public static function PreparePopupItems($entityTypeNames, $addPrefix = true, $nameFormat = '', $count = 50)
 {
     if (!is_array($entityTypeNames)) {
         $entityTypeNames = array(strval($entityTypeNames));
     }
     $addPrefix = (bool) $addPrefix;
     $count = intval($count);
     if ($count <= 0) {
         $count = 50;
     }
     $arItems = array();
     $i = 0;
     foreach ($entityTypeNames as $typeName) {
         $typeName = strtoupper(strval($typeName));
         if ($typeName === 'CONTACT') {
             $contactTypes = CCrmStatus::GetStatusList('CONTACT_TYPE');
             $contactIndex = array();
             $obRes = CCrmContact::GetListEx(array('ID' => 'DESC'), array(), false, array('nTopCount' => $count), array('ID', 'HONORIFIC', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'COMPANY_TITLE', 'PHOTO', 'TYPE_ID'));
             while ($arRes = $obRes->Fetch()) {
                 $arImg = array();
                 if (!empty($arRes['PHOTO']) && !isset($arFiles[$arRes['PHOTO']])) {
                     if (intval($arRes['PHOTO']) > 0) {
                         $arImg = CFile::ResizeImageGet($arRes['PHOTO'], array('width' => 25, 'height' => 25), BX_RESIZE_IMAGE_EXACT);
                     }
                 }
                 $arRes['SID'] = $addPrefix ? 'C_' . $arRes['ID'] : $arRes['ID'];
                 // advanced info
                 $advancedInfo = array();
                 if (isset($arRes['TYPE_ID']) && $arRes['TYPE_ID'] != '' && isset($contactTypes[$arRes['TYPE_ID']])) {
                     $advancedInfo['contactType'] = array('id' => $arRes['TYPE_ID'], 'name' => $contactTypes[$arRes['TYPE_ID']]);
                 }
                 $arItems[$i] = array('title' => CCrmContact::PrepareFormattedName(array('HONORIFIC' => isset($arRes['HONORIFIC']) ? $arRes['HONORIFIC'] : '', 'NAME' => isset($arRes['NAME']) ? $arRes['NAME'] : '', 'SECOND_NAME' => isset($arRes['SECOND_NAME']) ? $arRes['SECOND_NAME'] : '', 'LAST_NAME' => isset($arRes['LAST_NAME']) ? $arRes['LAST_NAME'] : ''), $nameFormat), 'desc' => empty($arRes['COMPANY_TITLE']) ? "" : $arRes['COMPANY_TITLE'], 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_contact_show'), array('contact_id' => $arRes['ID'])), 'image' => $arImg['src'], 'type' => 'contact', 'selected' => 'N');
                 if (!empty($advancedInfo)) {
                     $arItems[$i]['advancedInfo'] = $advancedInfo;
                 }
                 unset($advancedInfo);
                 $contactIndex[$arRes['ID']] =& $arItems[$i];
                 $i++;
             }
             // advanced info - phone number, e-mail
             $obRes = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'CONTACT', 'ELEMENT_ID' => array_keys($contactIndex)));
             while ($arRes = $obRes->Fetch()) {
                 if (isset($contactIndex[$arRes['ELEMENT_ID']]) && ($arRes['TYPE_ID'] === 'PHONE' || $arRes['TYPE_ID'] === 'EMAIL')) {
                     $item =& $contactIndex[$arRes['ELEMENT_ID']];
                     if (!is_array($item['advancedInfo'])) {
                         $item['advancedInfo'] = array();
                     }
                     if (!is_array($item['advancedInfo']['multiFields'])) {
                         $item['advancedInfo']['multiFields'] = array();
                     }
                     $item['advancedInfo']['multiFields'][] = array('ID' => $arRes['ID'], 'TYPE_ID' => $arRes['TYPE_ID'], 'VALUE_TYPE' => $arRes['VALUE_TYPE'], 'VALUE' => $arRes['VALUE']);
                     unset($item);
                 }
             }
             unset($contactIndex);
         } elseif ($typeName === 'COMPANY') {
             $companyIndex = array();
             $arCompanyTypeList = CCrmStatus::GetStatusListEx('COMPANY_TYPE');
             $arCompanyIndustryList = CCrmStatus::GetStatusListEx('INDUSTRY');
             $obRes = CCrmCompany::GetListEx(array('ID' => 'DESC'), array(), false, array('nTopCount' => $count), array('ID', 'TITLE', 'COMPANY_TYPE', 'INDUSTRY', 'LOGO'));
             $arFiles = array();
             while ($arRes = $obRes->Fetch()) {
                 $arImg = array();
                 if (!empty($arRes['LOGO']) && !isset($arFiles[$arRes['LOGO']])) {
                     if (intval($arRes['LOGO']) > 0) {
                         $arImg = CFile::ResizeImageGet($arRes['LOGO'], array('width' => 25, 'height' => 25), BX_RESIZE_IMAGE_EXACT);
                     }
                     $arFiles[$arRes['LOGO']] = $arImg['src'];
                 }
                 $arRes['SID'] = $addPrefix ? 'CO_' . $arRes['ID'] : $arRes['ID'];
                 $arDesc = array();
                 if (isset($arCompanyTypeList[$arRes['COMPANY_TYPE']])) {
                     $arDesc[] = $arCompanyTypeList[$arRes['COMPANY_TYPE']];
                 }
                 if (isset($arCompanyIndustryList[$arRes['INDUSTRY']])) {
                     $arDesc[] = $arCompanyIndustryList[$arRes['INDUSTRY']];
                 }
                 $arItems[$i] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => implode(', ', $arDesc), 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_company_show'), array('company_id' => $arRes['ID'])), 'image' => $arImg['src'], 'type' => 'company', 'selected' => 'N');
                 $companyIndex[$arRes['ID']] =& $arItems[$i];
                 $i++;
             }
             // advanced info - phone number, e-mail
             $obRes = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'COMPANY', 'ELEMENT_ID' => array_keys($companyIndex)));
             while ($arRes = $obRes->Fetch()) {
                 if (isset($companyIndex[$arRes['ELEMENT_ID']]) && ($arRes['TYPE_ID'] === 'PHONE' || $arRes['TYPE_ID'] === 'EMAIL')) {
                     $item =& $companyIndex[$arRes['ELEMENT_ID']];
                     if (!is_array($item['advancedInfo'])) {
                         $item['advancedInfo'] = array();
                     }
                     if (!is_array($item['advancedInfo']['multiFields'])) {
                         $item['advancedInfo']['multiFields'] = array();
                     }
                     $item['advancedInfo']['multiFields'][] = array('ID' => $arRes['ID'], 'TYPE_ID' => $arRes['TYPE_ID'], 'VALUE_TYPE' => $arRes['VALUE_TYPE'], 'VALUE' => $arRes['VALUE']);
                     unset($item);
                 }
             }
             unset($companyIndex);
         } elseif ($typeName === 'LEAD') {
             $leadIndex = array();
             $obRes = CCrmLead::GetListEx(array('ID' => 'DESC'), array(), false, array('nTopCount' => $count), array('ID', 'TITLE', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'STATUS_ID'));
             while ($arRes = $obRes->Fetch()) {
                 $arRes['SID'] = $addPrefix ? 'L_' . $arRes['ID'] : $arRes['ID'];
                 $arItems[$i] = array('title' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '', 'desc' => CCrmLead::PrepareFormattedName(array('HONORIFIC' => isset($arRes['HONORIFIC']) ? $arRes['HONORIFIC'] : '', 'NAME' => isset($arRes['NAME']) ? $arRes['NAME'] : '', 'SECOND_NAME' => isset($arRes['SECOND_NAME']) ? $arRes['SECOND_NAME'] : '', 'LAST_NAME' => isset($arRes['LAST_NAME']) ? $arRes['LAST_NAME'] : ''), $nameFormat), 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_show'), array('lead_id' => $arRes['ID'])), 'type' => 'lead', 'selected' => 'N');
                 $leadIndex[$arRes['ID']] =& $arItems[$i];
                 $i++;
             }
             // advanced info - phone number, e-mail
             $obRes = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'LEAD', 'ELEMENT_ID' => array_keys($leadIndex)));
             while ($arRes = $obRes->Fetch()) {
                 if (isset($leadIndex[$arRes['ELEMENT_ID']]) && ($arRes['TYPE_ID'] === 'PHONE' || $arRes['TYPE_ID'] === 'EMAIL')) {
                     $item =& $leadIndex[$arRes['ELEMENT_ID']];
                     if (!is_array($item['advancedInfo'])) {
                         $item['advancedInfo'] = array();
                     }
                     if (!is_array($item['advancedInfo']['multiFields'])) {
                         $item['advancedInfo']['multiFields'] = array();
                     }
                     $item['advancedInfo']['multiFields'][] = array('ID' => $arRes['ID'], 'TYPE_ID' => $arRes['TYPE_ID'], 'VALUE_TYPE' => $arRes['VALUE_TYPE'], 'VALUE' => $arRes['VALUE']);
                     unset($item);
                 }
             }
             unset($leadIndex);
         } elseif ($typeName === 'DEAL') {
             $obRes = CCrmDeal::GetListEx(array('ID' => 'DESC'), array(), false, array('nTopCount' => $count), array('ID', 'TITLE', 'STAGE_ID', 'COMPANY_TITLE', 'CONTACT_FULL_NAME'));
             while ($arRes = $obRes->Fetch()) {
                 $arRes['SID'] = $addPrefix ? 'D_' . $arRes['ID'] : $arRes['ID'];
                 $clientTitle = !empty($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : '';
                 $clientTitle .= ($clientTitle !== '' && !empty($arRes['CONTACT_FULL_NAME']) ? ', ' : '') . $arRes['CONTACT_FULL_NAME'];
                 $arItems[] = array('title' => isset($arRes['TITLE']) ? str_replace(array(';', ','), ' ', $arRes['TITLE']) : '', 'desc' => $clientTitle, 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_show'), array('deal_id' => $arRes['ID'])), 'type' => 'deal', 'selected' => 'N');
             }
         } elseif ($typeName === 'QUOTE') {
             $obRes = CCrmQuote::GetList(array('ID' => 'DESC'), array(), false, array('nTopCount' => $count), array('ID', 'QUOTE_NUMBER', 'TITLE', 'COMPANY_TITLE', 'CONTACT_FULL_NAME'));
             while ($arRes = $obRes->Fetch()) {
                 $arRes['SID'] = $addPrefix ? CCrmQuote::OWNER_TYPE . '_' . $arRes['ID'] : $arRes['ID'];
                 $clientTitle = !empty($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : '';
                 $clientTitle .= ($clientTitle !== '' && !empty($arRes['CONTACT_FULL_NAME']) ? ', ' : '') . $arRes['CONTACT_FULL_NAME'];
                 $quoteTitle = empty($arRes['TITLE']) ? $arRes['QUOTE_NUMBER'] : $arRes['QUOTE_NUMBER'] . ' - ' . $arRes['TITLE'];
                 $arItems[] = array('title' => empty($quoteTitle) ? '' : str_replace(array(';', ','), ' ', $quoteTitle), 'desc' => $clientTitle, 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_quote_show'), array('quote_id' => $arRes['ID'])), 'type' => 'quote', 'selected' => 'N');
             }
         }
     }
     unset($typeName);
     return $arItems;
 }
 private function SaveOrderDataDeal($arOrder, $contactId = null, $companyId = null)
 {
     $dealId = 0;
     $dealTitle = "";
     $dbDeal = CCrmDeal::GetList(array(), array("ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => $arOrder["ID"], "CHECK_PERMISSIONS" => "N"));
     if ($arDeal = $dbDeal->Fetch()) {
         $dealId = $arDeal["ID"];
         $dealTitle = $arDeal["TITLE"];
     }
     $newDeal = $dealId == 0;
     if ($this->arExternalSale == null) {
         $this->arExternalSale = CCrmExternalSale::GetDefaultSettings($this->externalSaleId);
     }
     $arFields = array('ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => $arOrder["ID"], 'BEGINDATE' => $arOrder["DATE_INSERT"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'EXCH_RATE' => $arOrder["CURRENCY_RATE"], 'OPPORTUNITY' => $arOrder["PRICE"]);
     // Prevent reset comment if order comment is empty
     if (isset($arOrder["COMMENT"]) && $arOrder["COMMENT"] !== "") {
         $arFields["COMMENTS"] = $arOrder["COMMENT"];
     }
     if ($contactId != null && intval($contactId) > 0) {
         $arFields["CONTACT_ID"] = $contactId;
     }
     if ($companyId != null && intval($companyId) > 0) {
         $arFields["COMPANY_ID"] = $companyId;
     }
     static $arStageList = null;
     if ($arStageList == null) {
         $arStageList = CCrmStatus::GetStatusList('DEAL_STAGE');
     }
     // Prevent reset stage for existed deals
     if ($newDeal && array_key_exists("NEW", $arStageList)) {
         $arFields["STAGE_ID"] = "NEW";
     }
     $arAdditionalInfo = array();
     if ($contactId != null && intval($contactId) > 0) {
         if (isset($arOrder["CONTRACTOR"]["FULL_NAME"]) && $arOrder["CONTRACTOR"]["FULL_NAME"] != "") {
             $arAdditionalInfo['CONTACT_FULL_NAME'] = $arOrder["CONTRACTOR"]["FULL_NAME"];
         } elseif (isset($arOrder["CONTRACTOR"]["NAME"]) && $arOrder["CONTRACTOR"]["NAME"] != "") {
             $arAdditionalInfo['CONTACT_FULL_NAME'] = $arOrder["CONTRACTOR"]["NAME"];
         }
     }
     if ($companyId != null && intval($companyId) > 0) {
         if (isset($arOrder["CONTRACTOR"]["OFFICIAL_NAME"]) && $arOrder["CONTRACTOR"]["OFFICIAL_NAME"] != "") {
             $arAdditionalInfo['COMPANY_FULL_NAME'] = $arOrder["CONTRACTOR"]["OFFICIAL_NAME"];
         } elseif (isset($arOrder["CONTRACTOR"]["NAME"]) && $arOrder["CONTRACTOR"]["NAME"] != "") {
             $arAdditionalInfo['COMPANY_FULL_NAME'] = $arOrder["CONTRACTOR"]["NAME"];
         }
     }
     if (is_array($arOrder["PROPERTIES"])) {
         foreach ($arOrder["PROPERTIES"] as $arProp) {
             if (!empty($arProp["VALUE"])) {
                 $arAdditionalInfo[strtoupper($arProp["NAME"])] = $arProp["VALUE"];
                 if ($arAdditionalInfo[strtoupper($arProp["NAME"])] == "true") {
                     $arAdditionalInfo[strtoupper($arProp["NAME"])] = true;
                 } elseif ($arAdditionalInfo[strtoupper($arProp["NAME"])] == "false") {
                     $arAdditionalInfo[strtoupper($arProp["NAME"])] = false;
                 }
             }
             switch (strtoupper($arProp["NAME"])) {
                 case 'FINALSTATUS':
                     if ($arProp["VALUE"] == 'true') {
                         $arFields["CLOSED"] = "Y";
                         //$arFields["CLOSEDATE"] = $arOrder["DATE_UPDATE"];
                     } else {
                         $arFields["CLOSED"] = "N";
                         //$arFields["CLOSEDATE"] = false;
                     }
                     break;
                 case 'CANCELED':
                     if ($arProp["VALUE"] == 'true') {
                         if (array_key_exists("LOSE", $arStageList)) {
                             $arFields["STAGE_ID"] = "LOSE";
                         }
                         $arFields["PROBABILITY"] = 0;
                     }
                     break;
                 case 'ORDERPAID':
                     if ($arProp["VALUE"] == 'true') {
                         if (array_key_exists("WON", $arStageList)) {
                             $arFields["STAGE_ID"] = "WON";
                         }
                         $arFields["PROBABILITY"] = 100;
                     }
                     break;
                 case 'ORDERSTATUS':
                     //$arFields["CLOSED"] = "Y";
                     //$arFields["CLOSEDATE"] = $arOrder["DATE_UPDATE"];
                     break;
             }
         }
     }
     $arFields["ADDITIONAL_INFO"] = serialize($arAdditionalInfo);
     $accountNumber = isset($arOrder["ACCOUNT_NUMBER"]) && $arOrder["ACCOUNT_NUMBER"] !== '' ? $arOrder["ACCOUNT_NUMBER"] : $arOrder["ID"];
     $obj = new CCrmDeal(false);
     if ($dealId == 0) {
         $arFields['TITLE'] = sprintf("%s #%s", $this->arExternalSale["PREFIX"], $accountNumber);
         $arFields['OPENED'] = $this->arExternalSale["PUBLIC"];
         $arFields["TYPE_ID"] = 'SALE';
         $arFields["CLOSEDATE"] = ConvertTimeStamp(time() + CTimeZone::GetOffset() + 86400, "FULL");
         if (!isset($arFields["PROBABILITY"])) {
             $arFields["PROBABILITY"] = $this->arExternalSale["PROBABILITY"];
         }
         $assignedById = $this->arExternalSale["RESPONSIBLE"];
         if ($assignedById > 0) {
             $arFields["ASSIGNED_BY_ID"] = $assignedById;
         }
         $res = $obj->Add($arFields, true, array('DISABLE_USER_FIELD_CHECK' => true));
         if ($res > 0) {
             $dealId = (int) $res;
             $this->arImportResult->numberOfCreatedDeals++;
         }
     } else {
         if ($dealTitle === 'Deal') {
             $arFields['TITLE'] = sprintf("%s #%s", $this->arExternalSale["PREFIX"], $accountNumber);
         }
         // Disable properties change events generation ($bCompare = false) and user fields check 'DISABLE_USER_FIELD_CHECK' = true.
         $res = $obj->Update($dealId, $arFields, false, true, array('DISABLE_USER_FIELD_CHECK' => true));
         if ($res) {
             $this->arImportResult->numberOfUpdatedDeals++;
         }
     }
     if (!$res) {
         if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
             $this->AddError($ex->GetID(), $ex->GetString());
         } else {
             $this->AddError("CDA", "Deal creation error");
         }
         if (!empty($obj->LAST_ERROR)) {
             $this->AddError("CDA", $obj->LAST_ERROR);
         }
         return false;
     }
     return array($dealId, $newDeal);
 }
Exemple #28
0
$arResult['TOOLBAR_ID'] = $toolbarID;
$arResult['BUTTONS'] = array();
if ($arParams['TYPE'] == 'list') {
    $bRead = !$CrmPerms->HavePerm('DEAL', BX_CRM_PERM_NONE, 'READ');
    $bExport = !$CrmPerms->HavePerm('DEAL', BX_CRM_PERM_NONE, 'EXPORT');
    $bImport = !$CrmPerms->HavePerm('DEAL', BX_CRM_PERM_NONE, 'IMPORT');
    $bAdd = !$CrmPerms->HavePerm('DEAL', BX_CRM_PERM_NONE, 'ADD');
    $bWrite = !$CrmPerms->HavePerm('DEAL', BX_CRM_PERM_NONE, 'WRITE');
    $bDelete = false;
} else {
    $bExport = false;
    $bImport = false;
    $bRead = CCrmDeal::CheckReadPermission($arParams['ELEMENT_ID'], $CrmPerms);
    $bAdd = CCrmDeal::CheckCreatePermission($CrmPerms);
    $bWrite = CCrmDeal::CheckUpdatePermission($arParams['ELEMENT_ID'], $CrmPerms);
    $bDelete = CCrmDeal::CheckDeletePermission($arParams['ELEMENT_ID'], $CrmPerms);
}
if (!$bRead && !$bAdd && !$bWrite) {
    return false;
}
if ($arParams['TYPE'] === 'list') {
    if ($bAdd) {
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('DEAL_ADD'), 'TITLE' => GetMessage('DEAL_ADD_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_DEAL_EDIT'], array('deal_id' => 0)), 'HIGHLIGHT' => true);
    }
    if ($bImport) {
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('DEAL_IMPORT'), 'TITLE' => GetMessage('DEAL_IMPORT_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_DEAL_IMPORT'], array()), 'ICON' => 'btn-import');
    }
    if ($bExport) {
        $arResult['BUTTONS'][] = array('TITLE' => GetMessage('DEAL_EXPORT_CSV_TITLE'), 'TEXT' => GetMessage('DEAL_EXPORT_CSV'), 'LINK' => CHTTP::urlAddParams(CComponentEngine::MakePathFromTemplate($APPLICATION->GetCurPage(), array()), array('type' => 'csv', 'ncc' => '1')), 'ICON' => 'btn-export');
        $arResult['BUTTONS'][] = array('TITLE' => GetMessage('DEAL_EXPORT_EXCEL_TITLE'), 'TEXT' => GetMessage('DEAL_EXPORT_EXCEL'), 'LINK' => CHTTP::urlAddParams(CComponentEngine::MakePathFromTemplate($APPLICATION->GetCurPage(), array()), array('type' => 'excel', 'ncc' => '1')), 'ICON' => 'btn-export');
    }
                $ar = explode('_', $value);
                $arValue[CUserTypeCrm::GetLongEntityType($ar[0])][] = intval($ar[1]);
            }
        }
    }
    $arResult['VALUE'] = array();
    if ($arParams['arUserField']['SETTINGS']['LEAD'] == 'Y' && isset($arValue['LEAD']) && !empty($arValue['LEAD'])) {
        $dbRes = CCrmLead::GetList(array('TITLE' => 'ASC', 'LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => $arValue['LEAD']));
        while ($arRes = $dbRes->Fetch()) {
            $arResult['VALUE']['LEAD'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['TITLE'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_show'), array('lead_id' => $arRes['ID'])));
        }
    }
    if ($arParams['arUserField']['SETTINGS']['CONTACT'] == 'Y' && isset($arValue['CONTACT']) && !empty($arValue['CONTACT'])) {
        $dbRes = CCrmContact::GetList(array('LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => $arValue['CONTACT']));
        while ($arRes = $dbRes->Fetch()) {
            $arResult['VALUE']['CONTACT'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['FULL_NAME'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_contact_show'), array('contact_id' => $arRes['ID'])));
        }
    }
    if ($arParams['arUserField']['SETTINGS']['COMPANY'] == 'Y' && isset($arValue['COMPANY']) && !empty($arValue['COMPANY'])) {
        $dbRes = CCrmCompany::GetList(array('TITLE' => 'ASC'), array('ID' => $arValue['COMPANY']));
        while ($arRes = $dbRes->Fetch()) {
            $arResult['VALUE']['COMPANY'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['TITLE'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_company_show'), array('company_id' => $arRes['ID'])));
        }
    }
    if ($arParams['arUserField']['SETTINGS']['DEAL'] == 'Y' && isset($arValue['DEAL']) && !empty($arValue['DEAL'])) {
        $dbRes = CCrmDeal::GetList(array('TITLE' => 'ASC'), array('ID' => $arValue['DEAL']));
        while ($arRes = $dbRes->Fetch()) {
            $arResult['VALUE']['DEAL'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['TITLE'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_show'), array('deal_id' => $arRes['ID'])));
        }
    }
}
Exemple #30
0
 public static function PrepareConversionPermissionFlags($ID, array &$params, $userPermissions = null)
 {
     if (!$userPermissions) {
         $userPermissions = CCrmPerms::GetCurrentUserPermissions();
     }
     $canCreateDeal = CCrmDeal::CheckCreatePermission($userPermissions);
     $canCreateInvoice = IsModuleInstalled('sale') && CCrmInvoice::CheckCreatePermission($userPermissions);
     $params['CAN_CONVERT_TO_DEAL'] = $canCreateDeal;
     $params['CAN_CONVERT_TO_INVOICE'] = $canCreateInvoice;
     $params['CAN_CONVERT'] = $params['CONVERT'] = $canCreateInvoice || $canCreateDeal;
     $restriction = \Bitrix\Crm\Restriction\RestrictionManager::getConversionRestriction();
     if ($restriction->hasPermission()) {
         $params['CONVERSION_PERMITTED'] = true;
     } else {
         $params['CONVERSION_PERMITTED'] = false;
         $params['CONVERSION_LOCK_SCRIPT'] = $restriction->preparePopupScript();
     }
 }