Esempio n. 1
0
 public static function PreparePopupItems($currencyID = '', $count = 50, $enableRawPrices = false)
 {
     $currencyID = strval($currencyID);
     if (!isset($currencyID[0])) {
         $currencyID = CCrmCurrency::GetBaseCurrencyID();
     }
     $count = intval($count);
     if ($count <= 0) {
         $count = 50;
     }
     $arSelect = array('ID', 'NAME', 'PRICE', 'CURRENCY_ID');
     $arPricesSelect = $arVatsSelect = array();
     $arSelect = CCrmProduct::DistributeProductSelect($arSelect, $arPricesSelect, $arVatsSelect);
     $rs = CCrmProduct::GetList(array('ID' => 'DESC'), array('ACTIVE' => 'Y', 'CATALOG_ID' => CCrmCatalog::EnsureDefaultExists()), $arSelect, $count);
     $arProducts = array();
     $arProductId = array();
     while ($product = $rs->Fetch()) {
         foreach ($arPricesSelect as $fieldName) {
             $product[$fieldName] = null;
         }
         foreach ($arVatsSelect as $fieldName) {
             $product[$fieldName] = null;
         }
         $arProductId[] = $product['ID'];
         $arProducts[$product['ID']] = $product;
     }
     CCrmProduct::ObtainPricesVats($arProducts, $arProductId, $arPricesSelect, $arVatsSelect, $enableRawPrices);
     $measureInfos = \Bitrix\Crm\Measure::getProductMeasures($arProductId);
     $productVatInfos = CCrmProduct::PrepareCatalogProductFields($arProductId);
     unset($arProductId, $arPricesSelect, $arVatsSelect);
     $defaultMeasureInfo = \Bitrix\Crm\Measure::getDefaultMeasure();
     $result = array();
     foreach ($arProducts as $productID => &$product) {
         if ($currencyID != $product['CURRENCY_ID']) {
             $product['PRICE'] = CCrmCurrency::ConvertMoney($product['PRICE'], $product['CURRENCY_ID'], $currencyID);
             $product['CURRENCY_ID'] = $currencyID;
         }
         $customData = array('price' => $product['PRICE']);
         if (isset($measureInfos[$productID]) && !empty($measureInfos[$productID])) {
             $measureIfo = $measureInfos[$productID][0];
             $customData['measure'] = array('code' => $measureIfo['CODE'], 'name' => $measureIfo['SYMBOL']);
         } elseif ($defaultMeasureInfo !== null) {
             $customData['measure'] = array('code' => $defaultMeasureInfo['CODE'], 'name' => $defaultMeasureInfo['SYMBOL']);
         }
         if (isset($productVatInfos[$productID])) {
             $productVatInfo = $productVatInfos[$productID];
             $customData['tax'] = array('id' => $productVatInfo['TAX_ID'], 'included' => $enableRawPrices && $productVatInfo['TAX_INCLUDED']);
         }
         $result[] = array('title' => $product['NAME'], 'desc' => CCrmProduct::FormatPrice($product), 'id' => $product['ID'], 'url' => '', 'type' => 'product', 'selected' => false, 'customData' => &$customData);
         unset($customData);
     }
     unset($product, $arProducts);
     return $result;
 }
Esempio n. 2
0
        $arSelect = array('ID', 'NAME', 'PRICE', 'CURRENCY_ID');
        $arPricesSelect = $arVatsSelect = array();
        $arSelect = CCrmProduct::DistributeProductSelect($arSelect, $arPricesSelect, $arVatsSelect);
        $obRes = CCrmProduct::GetList(array('ID' => 'DESC'), array('ID' => $arSelected['PRODUCT']), $arSelect);
        $arProducts = $arProductId = array();
        while ($arRes = $obRes->Fetch()) {
            foreach ($arPricesSelect as $fieldName) {
                $arRes[$fieldName] = null;
            }
            foreach ($arVatsSelect as $fieldName) {
                $arRes[$fieldName] = null;
            }
            $arProductId[] = $arRes['ID'];
            $arProducts[$arRes['ID']] = $arRes;
        }
        CCrmProduct::ObtainPricesVats($arProducts, $arProductId, $arPricesSelect, $arVatsSelect);
        unset($arProductId, $arPricesSelect, $arVatsSelect);
        foreach ($arProducts as $arRes) {
            $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';
            }
            $ar[] = array('title' => $arRes['NAME'], 'desc' => CCrmProduct::FormatPrice($arRes), 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_product_show'), array('product_id' => $arRes['ID'])), 'type' => 'product', 'selected' => $sSelected);
        }
        unset($arProducts);
        $arResult['ELEMENT'] = array_merge($ar, $arResult['ELEMENT']);
    }
}
Esempio n. 3
0
    }
    foreach ($arVatsSelect as $fieldName) {
        $arRes[$fieldName] = null;
    }
    $nameUpper = ToUpper($arRes['NAME']);
    $pos = strpos($nameUpper, $searchUpper);
    $arRes['RANK1'] = $pos === false ? 0 : $pos + 1;
    $arProductId[] = $arRes['ID'];
    $arProducts[$arRes['ID']] = $arRes;
    $arSort['RANK1'][] = $arRes['RANK1'];
    $arSort['NAME'][] = $nameUpper;
    $arSort['ID'][] = $arRes['ID'];
}
array_multisort($arSort['RANK1'], SORT_NUMERIC, SORT_ASC, $arSort['NAME'], SORT_STRING, SORT_ASC, $arSort['ID'], SORT_NUMERIC, SORT_ASC);
unset($arSort['RANK1'], $arSort['NAME']);
CCrmProduct::ObtainPricesVats($arProducts, $arProductId, $arPricesSelect, $arVatsSelect, $enableRawPrices);
$measureInfos = \Bitrix\Crm\Measure::getProductMeasures($arProductId);
$productVatInfos = CCrmProduct::PrepareCatalogProductFields($arProductId);
unset($arProductId);
$defaultMeasureInfo = \Bitrix\Crm\Measure::getDefaultMeasure();
$i = 0;
foreach ($arSort['ID'] as $id) {
    $arRes = $arProducts[$id];
    $srcCurrencyID = isset($arRes['CURRENCY_ID']) ? $arRes['CURRENCY_ID'] : 0;
    if (strlen($dstCurrencyID) > 0 && strlen($srcCurrencyID) > 0 && $dstCurrencyID != $srcCurrencyID) {
        $arRes['PRICE'] = CCrmCurrency::ConvertMoney($arRes['PRICE'], $srcCurrencyID, $dstCurrencyID);
        $arRes['CURRENCY_ID'] = $dstCurrencyID;
    }
    $productID = $arRes['ID'];
    $customData = array('price' => $arRes['PRICE']);
    if (isset($measureInfos[$productID]) && !empty($measureInfos[$productID])) {
Esempio n. 4
0
 protected function prepareCrmSelectorItem($ufInfo)
 {
     /** @global CUser $USER */
     global $USER;
     $result = false;
     $selectorItem = array();
     if (!CModule::IncludeModule('crm')) {
         return $result;
     }
     $CCrmPerms = new CCrmPerms($USER->GetID());
     $nPermittedEntityTypes = 0;
     if ($ufInfo['SETTINGS']['LEAD'] == 'Y' && !$CCrmPerms->HavePerm('LEAD', BX_CRM_PERM_NONE, 'READ')) {
         $nPermittedEntityTypes++;
     }
     if ($ufInfo['SETTINGS']['CONTACT'] == 'Y' && !$CCrmPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'READ')) {
         $nPermittedEntityTypes++;
     }
     if ($ufInfo['SETTINGS']['COMPANY'] == 'Y' && !$CCrmPerms->HavePerm('COMPANY', BX_CRM_PERM_NONE, 'READ')) {
         $nPermittedEntityTypes++;
     }
     if ($ufInfo['SETTINGS']['DEAL'] == 'Y' && !$CCrmPerms->HavePerm('DEAL', BX_CRM_PERM_NONE, 'READ')) {
         $nPermittedEntityTypes++;
     }
     if ($ufInfo['SETTINGS']['QUOTE'] == 'Y' && !$CCrmPerms->HavePerm('QUOTE', BX_CRM_PERM_NONE, 'READ')) {
         $nPermittedEntityTypes++;
     }
     if ($ufInfo['SETTINGS']['PRODUCT'] == 'Y' && $CCrmPerms->HavePerm('CONFIG', BX_CRM_PERM_CONFIG, 'READ')) {
         $nPermittedEntityTypes++;
     }
     $usePrefix = true;
     /*$nPermittedEntityTypes > 1;*/
     // last 50 entity
     $entityTypes = array();
     $elements = array();
     $arSettings = $ufInfo['SETTINGS'];
     if (isset($arSettings['LEAD']) && $arSettings['LEAD'] == 'Y') {
         $entityTypes[] = 'lead';
         $arSelect = array('ID', 'TITLE', 'FULL_NAME', 'STATUS_ID');
         $obRes = CCrmLead::GetList(array('ID' => 'DESC'), array(), $arSelect, 50);
         $arFiles = array();
         while ($arRes = $obRes->Fetch()) {
             $arRes['SID'] = $usePrefix ? 'L_' . $arRes['ID'] : $arRes['ID'];
             $elements[] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => $arRes['FULL_NAME'], 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_show'), array('lead_id' => $arRes['ID'])), 'type' => 'lead', 'selected' => 'N');
         }
     }
     if (isset($arSettings['CONTACT']) && $arSettings['CONTACT'] == 'Y') {
         $entityTypes[] = 'contact';
         $arSelect = array('ID', 'FULL_NAME', 'COMPANY_TITLE', 'PHOTO');
         $obRes = CCrmContact::GetList(array('ID' => 'DESC'), array(), $arSelect, 50);
         while ($arRes = $obRes->Fetch()) {
             $strImg = '';
             if (!empty($arRes['PHOTO']) && !isset($arFiles[$arRes['PHOTO']])) {
                 if ($arFile = CFile::GetFileArray($arRes['PHOTO'])) {
                     $arImg = CFile::ResizeImageGet($arFile, array('width' => 25, 'height' => 25), BX_RESIZE_IMAGE_EXACT);
                     if (is_array($arImg) && isset($arImg['src'])) {
                         $strImg = CHTTP::URN2URI($arImg['src'], '', true);
                     }
                 }
             }
             $arRes['SID'] = $usePrefix ? 'C_' . $arRes['ID'] : $arRes['ID'];
             $elements[] = array('title' => str_replace(array(';', ','), ' ', $arRes['FULL_NAME']), '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' => $strImg, 'type' => 'contact', 'selected' => 'N');
         }
     }
     if (isset($arSettings['COMPANY']) && $arSettings['COMPANY'] == 'Y') {
         $entityTypes[] = 'company';
         $arCompanyTypeList = CCrmStatus::GetStatusListEx('COMPANY_TYPE');
         $arCompanyIndustryList = CCrmStatus::GetStatusListEx('INDUSTRY');
         $arSelect = array('ID', 'TITLE', 'COMPANY_TYPE', 'INDUSTRY', 'LOGO');
         $obRes = CCrmCompany::GetList(array('ID' => 'DESC'), array(), $arSelect, 50);
         $arFiles = array();
         while ($arRes = $obRes->Fetch()) {
             $strImg = '';
             if (!empty($arRes['LOGO']) && !isset($arFiles[$arRes['LOGO']])) {
                 if ($arFile = CFile::GetFileArray($arRes['LOGO'])) {
                     $arImg = CFile::ResizeImageGet($arFile, array('width' => 25, 'height' => 25), BX_RESIZE_IMAGE_EXACT);
                     if (is_array($arImg) && isset($arImg['src'])) {
                         $strImg = CHTTP::URN2URI($arImg['src'], '', true);
                     }
                 }
                 $arFiles[$arRes['LOGO']] = $strImg;
             }
             $arRes['SID'] = $usePrefix ? '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']];
             }
             $elements[] = 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' => $strImg, 'type' => 'company', 'selected' => 'N');
         }
     }
     if (isset($arSettings['DEAL']) && $arSettings['DEAL'] == 'Y') {
         $entityTypes[] = 'deal';
         $arDealStageList = CCrmStatus::GetStatusListEx('DEAL_STAGE');
         $arSelect = array('ID', 'TITLE', 'STAGE_ID', 'COMPANY_TITLE', 'CONTACT_FULL_NAME');
         $obRes = CCrmDeal::GetList(array('ID' => 'DESC'), array(), $arSelect, 50);
         while ($arRes = $obRes->Fetch()) {
             $arRes['SID'] = $usePrefix ? 'D_' . $arRes['ID'] : $arRes['ID'];
             $clientTitle = !empty($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : '';
             $clientTitle .= ($clientTitle !== '' && !empty($arRes['CONTACT_FULL_NAME']) ? ', ' : '') . $arRes['CONTACT_FULL_NAME'];
             $elements[] = 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' => 'N');
         }
     }
     if (isset($arSettings['QUOTE']) && $arSettings['QUOTE'] == 'Y') {
         $entityTypes[] = 'quote';
         $arSelect = array('ID', 'QUOTE_NUMBER', 'TITLE', 'COMPANY_TITLE', 'CONTACT_FULL_NAME');
         $obRes = CCrmQuote::GetList(array('ID' => 'DESC'), array(), false, array('nTopCount' => 50), array('ID', 'QUOTE_NUMBER', 'TITLE', 'COMPANY_TITLE', 'CONTACT_FULL_NAME'));
         while ($arRes = $obRes->Fetch()) {
             $arRes['SID'] = $usePrefix ? 'Q_' . $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'];
             $elements[] = 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');
         }
     }
     if (isset($arSettings['PRODUCT']) && $arSettings['PRODUCT'] == 'Y') {
         $entityTypes[] = 'product';
         $arSelect = array('ID', 'NAME', 'PRICE', 'CURRENCY_ID');
         $arPricesSelect = $arVatsSelect = array();
         $arSelect = CCrmProduct::DistributeProductSelect($arSelect, $arPricesSelect, $arVatsSelect);
         $obRes = CCrmProduct::GetList(array('ID' => 'DESC'), array('ACTIVE' => 'Y'), $arSelect, 50);
         $arProducts = $arProductId = array();
         while ($arRes = $obRes->Fetch()) {
             foreach ($arPricesSelect as $fieldName) {
                 $arRes[$fieldName] = null;
             }
             foreach ($arVatsSelect as $fieldName) {
                 $arRes[$fieldName] = null;
             }
             $arProductId[] = $arRes['ID'];
             $arProducts[$arRes['ID']] = $arRes;
         }
         CCrmProduct::ObtainPricesVats($arProducts, $arProductId, $arPricesSelect, $arVatsSelect);
         unset($arProductId, $arPricesSelect, $arVatsSelect);
         foreach ($arProducts as $arRes) {
             $arRes['SID'] = $usePrefix ? 'PROD_' . $arRes['ID'] : $arRes['ID'];
             $elements[] = array('title' => $arRes['NAME'], 'desc' => CCrmProduct::FormatPrice($arRes), 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_product_show'), array('product_id' => $arRes['ID'])), 'type' => 'product', 'selected' => 'N');
         }
         unset($arProducts);
     }
     $selectorItem['USER_TYPE_ID'] = $ufInfo['USER_TYPE_ID'];
     $selectorItem['ENTITY_ID'] = $ufInfo['ENTITY_ID'];
     $selectorItem['FIELD_NAME'] = $ufInfo['FIELD_NAME'];
     $selectorItem['PREFIX'] = $usePrefix ? 'Y' : 'N';
     $selectorItem['MULTIPLE'] = 'Y';
     //$ufInfo['MULTIPLE'];
     $selectorItem['ENTITY_TYPE'] = $entityTypes;
     $selectorItem['ELEMENT'] = $elements;
     $result = $selectorItem;
     return $result;
 }
Esempio n. 5
0
 public function getList($order, $filter, $select, $start)
 {
     if (!CCrmProduct::CheckReadPermission(0)) {
         throw new RestException('Access denied.');
     }
     $catalogID = CCrmCatalog::GetDefaultID();
     if ($catalogID <= 0) {
         $result = array();
         $dbResult = new CDBResult();
         $dbResult->InitFromArray($result);
         return CCrmRestService::setNavData($result, $dbResult);
     }
     $navigation = CCrmRestService::getNavData($start);
     if (!is_array($order) || empty($order)) {
         $order = array('sort' => 'asc');
     }
     if (!isset($navigation['bShowAll'])) {
         $navigation['bShowAll'] = false;
     }
     $enableCatalogData = false;
     $catalogSelect = null;
     $priceSelect = null;
     $vatSelect = null;
     if (is_array($select)) {
         if (!empty($select)) {
             // Remove '*' for get rid of inefficient construction of price data
             foreach ($select as $k => $v) {
                 if ($v === '*') {
                     unset($select[$k]);
                     break;
                 }
             }
         }
         if (empty($select)) {
             $priceSelect = array('PRICE', 'CURRENCY_ID');
             $vatSelect = array('VAT_ID', 'VAT_INCLUDED', 'MEASURE');
         } else {
             $priceSelect = array();
             $vatSelect = array();
             $select = CCrmProduct::DistributeProductSelect($select, $priceSelect, $vatSelect);
         }
         $catalogSelect = array_merge($priceSelect, $vatSelect);
         $enableCatalogData = !empty($catalogSelect);
     }
     $filter['CATALOG_ID'] = $catalogID;
     $dbResult = CCrmProduct::GetList($order, $filter, $select, $navigation);
     if (!$enableCatalogData) {
         $result = array();
         $fieldsInfo = $this->getFieldsInfo();
         while ($fields = $dbResult->Fetch()) {
             $this->externalizeFields($fields, $fieldsInfo);
             $result[] = $fields;
         }
     } else {
         $itemMap = array();
         $itemIDs = array();
         while ($fields = $dbResult->Fetch()) {
             foreach ($catalogSelect as $fieldName) {
                 $fields[$fieldName] = null;
             }
             $itemID = isset($fields['ID']) ? intval($fields['ID']) : 0;
             if ($itemID > 0) {
                 $itemIDs[] = $itemID;
                 $itemMap[$itemID] = $fields;
             }
         }
         CCrmProduct::ObtainPricesVats($itemMap, $itemIDs, $priceSelect, $vatSelect, true);
         $result = array_values($itemMap);
         $fieldsInfo = $this->getFieldsInfo();
         foreach ($result as &$fields) {
             $this->externalizeFields($fields, $fieldsInfo);
         }
         unset($fields);
     }
     return CCrmRestService::setNavData($result, $dbResult);
 }
Esempio n. 6
0
                    $arPropertyValues[$arElement['ID']][$propID][] = call_user_func_array($arPropUserTypeList[$arProperty['USER_TYPE']]["GetPublicViewHTML"], array($arProps[$propID], array("VALUE" => $arProperty["VALUE"]), array()));
                } else {
                    if ($arProperty["PROPERTY_TYPE"] == "L") {
                        $arPropertyValues[$arElement['ID']][$propID][] = htmlspecialcharsex($arProperty["VALUE_ENUM"]);
                    } else {
                        $arPropertyValues[$arElement['ID']][$propID][] = htmlspecialcharsex($arProperty["VALUE"]);
                    }
                }
            }
            unset($rsProperties, $arProperty, $propID);
        }
    }
}
$arResult['PROPERTY_VALUES'] = $arPropertyValues;
unset($arPropertyValues);
CCrmProduct::ObtainPricesVats($arResult['PRODUCTS'], $arProductId, $arPricesSelect, $arVatsSelect, isset($arFilter['~REAL_PRICE']) && $arFilter['~REAL_PRICE'] === true);
$productMeasureInfos = \Bitrix\Crm\Measure::getProductMeasures($arProductId);
if (!is_array($productMeasureInfos)) {
    $productMeasureInfos = array();
}
$arResult['PRODUCT_MEASURE_INFOS'] = $productMeasureInfos;
// <-- PRODUCTS
$arResult['ROWS_COUNT'] = $obRes->SelectedRowsCount();
$arResult['NAV_OBJECT'] = $obRes;
$arResult['BACK_URL_SECTION_ID'] = $bFilterSection ? $sectionID : '';
$this->IncludeComponentTemplate();
include_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/components/bitrix/crm.product/include/nav.php';
$result = array('ROWS_COUNT' => $arResult['ROWS_COUNT']);
if ($bFilterSection) {
    $result['SECTION_ID'] = $sectionID;
}