示例#1
0
 protected function parseParams()
 {
     $this->arParams['PATH_TO_PRODUCT_LIST'] = CrmCheckPath('PATH_TO_PRODUCT_LIST', $this->arParams['PATH_TO_PRODUCT_LIST'], $this->getApp()->GetCurPage() . '?section_id=#section_id#');
     // prepare URI template
     $matches = array();
     $curParam = $this->getApp()->GetCurParam();
     $curParam = preg_replace('/(?<!\\w)list_section_id=\\d*(?=([^\\d]|$))/', 'list_section_id=#section_id#', $curParam);
     $curParam = preg_replace('/(^|&)tree=\\w*(?=(&|$))/', '', $curParam);
     $this->arParams['PAGE_URI_TEMPLATE'] = $this->arParams['PATH_TO_PRODUCT_LIST'] . (strlen($curParam) > 0 ? '?' . $curParam . '&tree=Y' : '?tree=Y');
     unset($curParam);
     // Catalog ID
     if (isset($this->arParams['CATALOG_ID'])) {
         $this->catalogId = intval($this->arParams['CATALOG_ID']);
     }
     if ($this->catalogId <= 0) {
         $this->catalogId = CCrmCatalog::GetDefaultID();
     }
     // Section ID
     if (isset($this->arParams['SECTION_ID'])) {
         $this->sectionId = intval($this->arParams['SECTION_ID']);
     }
     if ($this->sectionId < 0) {
         $this->sectionId = 0;
     }
     // JS events mode
     if (isset($this->arParams['JS_EVENTS_MODE']) && $this->arParams['JS_EVENTS_MODE'] === 'Y') {
         $this->jsEventsMode = true;
     }
     // JS events manager
     $this->jsEventsManagerId = isset($this->arParams['JS_EVENTS_MANAGER_ID']) ? strval($this->arParams['JS_EVENTS_MANAGER_ID']) : '';
     return true;
 }
 public function __construct($catalogID = 0)
 {
     if ($catalogID <= 0) {
         $catalogID = CCrmCatalog::EnsureDefaultExists();
     }
     $this->catalogID = $catalogID;
     $this->sectionByNameCache = array();
     $this->iblockModuleIncluded = CModule::IncludeModule('iblock');
 }
 public static function PrepareCatalogListItems($addNotSelected = true)
 {
     IncludeModuleLangFile(__FILE__);
     $result = array();
     if ($addNotSelected) {
         $result['0'] = GetMessage('CRM_PRODUCT_CATALOG_NOT_SELECTED');
     }
     $rs = CCrmCatalog::GetList(array('NAME' => 'ASC'), array(), array('ID', 'NAME'));
     while ($ar = $rs->Fetch()) {
         $result[$ar['ID']] = $ar['NAME'];
     }
     return $result;
 }
示例#4
0
 public function executeComponent()
 {
     if (!CModule::IncludeModule('crm')) {
         ShowError(GetMessage('CRM_MODULE_NOT_INSTALLED'));
         return;
     }
     $catalogID = isset($this->arParams['CATALOG_ID']) ? intval($this->arParams['CATALOG_ID']) : 0;
     if ($catalogID <= 0) {
         $catalogID = CCrmCatalog::EnsureDefaultExists();
     }
     $this->arResult['CATALOG_ID'] = $catalogID;
     $this->arResult['JS_EVENTS_MANAGER_ID'] = isset($this->arParams['JS_EVENTS_MANAGER_ID']) ? $this->arParams['JS_EVENTS_MANAGER_ID'] : '';
     if (!is_string($this->arResult['JS_EVENTS_MANAGER_ID']) || $this->arResult['JS_EVENTS_MANAGER_ID'] === '') {
         return;
     }
     $this->includeComponentTemplate();
 }
示例#5
0
 public static function Create($catalogID = 0, $currencyID = '')
 {
     IncludeModuleLangFile(__FILE__);
     $catalogID = intval($catalogID);
     if ($catalogID <= 0) {
         $catalogID = CCrmCatalog::EnsureDefaultExists();
     }
     $currencyID = strval($currencyID);
     if ($currencyID === '') {
         $currencyID = CCrmCurrency::GetBaseCurrencyID();
     }
     $sectionID = self::EnsureProductSection('CRM_DEMO_SECTION_PRODUCTS', $catalogID, array('NAME' => GetMessage('CRM_DEMO_SECTION_PRODUCTS')));
     self::EnsureProduct('CRM_DEMO_PRODUCT_BX_CMS', $catalogID, array('CATALOG_ID' => $catalogID, 'SECTION_ID' => $sectionID, 'NAME' => GetMessage('CRM_DEMO_PRODUCT_BX_CMS'), 'CURRENCY_ID' => $currencyID, 'PRICE' => self::ConvertMoney(10000, 'RUB', $currencyID), 'ACTIVE' => 'Y', 'SORT' => 100));
     self::EnsureProduct('CRM_DEMO_PRODUCT_BX_CP', $catalogID, array('CATALOG_ID' => $catalogID, 'SECTION_ID' => $sectionID, 'NAME' => GetMessage('CRM_DEMO_PRODUCT_BX_CP'), 'CURRENCY_ID' => $currencyID, 'PRICE' => self::ConvertMoney(25000, 'RUB', $currencyID), 'ACTIVE' => 'Y', 'SORT' => 110));
     self::EnsureProduct('CRM_DEMO_PRODUCT_BX_TEAM', $catalogID, array('CATALOG_ID' => $catalogID, 'SECTION_ID' => $sectionID, 'NAME' => GetMessage('CRM_DEMO_PRODUCT_BX_TEAM'), 'CURRENCY_ID' => $currencyID, 'PRICE' => self::ConvertMoney(5000, 'RUB', $currencyID), 'ACTIVE' => 'Y', 'SORT' => 120));
     $sectionID = self::EnsureProductSection('CRM_DEMO_SECTION_SERVICES', $catalogID, array('NAME' => GetMessage('CRM_DEMO_SECTION_SERVICES')));
     self::EnsureProduct('CRM_DEMO_SERVICE_SITE_DISIGN', $catalogID, array('CATALOG_ID' => $catalogID, 'SECTION_ID' => $sectionID, 'NAME' => GetMessage('CRM_DEMO_SERVICE_SITE_DISIGN'), 'CURRENCY_ID' => $currencyID, 'PRICE' => self::ConvertMoney(15000, 'RUB', $currencyID), 'ACTIVE' => 'Y', 'SORT' => 130));
     self::EnsureProduct('CRM_DEMO_SERVICE_SITE_TUNING', $catalogID, array('CATALOG_ID' => $catalogID, 'SECTION_ID' => $sectionID, 'NAME' => GetMessage('CRM_DEMO_SERVICE_SITE_TUNING'), 'CURRENCY_ID' => $currencyID, 'PRICE' => self::ConvertMoney(20000, 'RUB', $currencyID), 'ACTIVE' => 'Y', 'SORT' => 140));
     self::EnsureProduct('CRM_DEMO_SERVICE_MANAGER_TRAINING', $catalogID, array('CATALOG_ID' => $catalogID, 'SECTION_ID' => $sectionID, 'NAME' => GetMessage('CRM_DEMO_SERVICE_MANAGER_TRAINING'), 'CURRENCY_ID' => $currencyID, 'PRICE' => self::ConvertMoney(5000, 'RUB', $currencyID), 'ACTIVE' => 'Y', 'SORT' => 150));
 }
示例#6
0
}
unset($arFields, $fieldID, $obFile, $obFileControl, $html, $fieldValue);
$visibleFields = array();
$productFormOptions = CUserOptions::GetOption('main.interface.form', 'CRM_PRODUCT_EDIT', array());
if (is_array($productFormOptions) && is_array($productFormOptions['tabs']) && count($productFormOptions['tabs']) && (!isset($productFormOptions['settings_disabled']) || $productFormOptions['settings_disabled'] !== 'Y')) {
    $tabFound = false;
    $tab = null;
    foreach ($productFormOptions['tabs'] as $tab) {
        if (isset($tab['id']) && $tab['id'] === 'tab_1') {
            $tabFound = true;
            break;
        }
    }
    if ($tabFound) {
        if (is_array($tab) && is_array($tab['fields'])) {
            foreach ($tab['fields'] as $field) {
                if (isset($field['type']) && isset($field['id']) && $field['type'] !== 'section') {
                    $visibleFields[] = $field['id'];
                }
            }
        }
    }
}
$arResult['PRODUCT_CREATE_DLG_VISIBLE_FIELDS'] = $visibleFields;
unset($productFormOptions);
$arResult['PRODUCT_CREATE_DLG_SETTINGS'] = array('formId' => 'crm_product_create_dialog_form', 'url' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_PRODUCT_EDIT'], array('product_id' => 0)), 'sessid' => bitrix_sessid(), 'messages' => array('dialogTitle' => GetMessage('CRM_PRODUCT_CREATE'), 'waitMessage' => GetMessage('CRM_PRODUCT_CREATE_WAIT'), 'ajaxError' => GetMessage('CRM_PRODUCT_CREATE_AJAX_ERR'), 'buttonCreateTitle' => GetMessage('CRM_BUTTON_CREATE_TITLE'), 'buttonCancelTitle' => GetMessage('CRM_BUTTON_CANCEL_TITLE'), 'NAME' => GetMessage('CRM_FIELD_PRODUCT_NAME'), 'DESCRIPTION' => GetMessage('CRM_FIELD_DESCRIPTION'), 'ACTIVE' => GetMessage('CRM_FIELD_ACTIVE'), 'CURRENCY' => GetMessage('CRM_FIELD_CURRENCY'), 'PRICE' => GetMessage('CRM_FIELD_PRICE'), 'MEASURE' => GetMessage('CRM_FIELD_MEASURE'), 'VAT_ID' => GetMessage('CRM_FIELD_VAT_ID'), 'VAT_INCLUDED' => GetMessage('CRM_FIELD_VAT_INCLUDED'), 'SECTION' => GetMessage('CRM_FIELD_SECTION'), 'SORT' => GetMessage('CRM_FIELD_SORT'), 'PREVIEW_PICTURE' => GetMessage('CRM_PRODUCT_FIELD_PREVIEW_PICTURE'), 'DETAIL_PICTURE' => GetMessage('CRM_PRODUCT_FIELD_DETAIL_PICTURE')), 'fields' => array(array('textCode' => 'NAME', 'type' => 'text', 'maxLength' => 255, 'value' => '', 'skip' => 'N', 'required' => 'Y'), array('textCode' => 'DESCRIPTION', 'type' => 'textarea', 'maxLength' => 7500, 'value' => '', 'skip' => !CCrmProductHelper::IsFieldVisible('DESCRIPTION', $visibleFields) ? 'Y' : 'N'), array('textCode' => 'ACTIVE', 'type' => 'checkbox', 'value' => 'Y', 'skip' => 'Y'), array('textCode' => 'CURRENCY', 'type' => 'select', 'value' => CCrmCurrency::GetBaseCurrencyID(), 'items' => CCrmViewHelper::prepareSelectItemsForJS(CCrmCurrencyHelper::PrepareListItems()), 'skip' => !CCrmProductHelper::IsFieldVisible('CURRENCY', $visibleFields) ? 'Y' : 'N'), array('textCode' => 'PRICE', 'type' => 'text', 'maxLength' => 21, 'value' => '0.00', 'skip' => !CCrmProductHelper::IsFieldVisible('PRICE', $visibleFields) ? 'Y' : 'N'), array('textCode' => 'MEASURE', 'type' => 'select', 'value' => '', 'items' => CCrmViewHelper::prepareSelectItemsForJS($measureListItems), 'skip' => !CCrmProductHelper::IsFieldVisible('MEASURE', $visibleFields) ? 'Y' : 'N'), array('textCode' => 'VAT_ID', 'type' => 'select', 'value' => '', 'items' => $arResult['ALLOW_TAX'] ? CCrmViewHelper::prepareSelectItemsForJS(CCrmVat::GetVatRatesListItems()) : null, 'skip' => $arResult['ALLOW_TAX'] ? !CCrmProductHelper::IsFieldVisible('VAT_ID', $visibleFields) ? 'Y' : 'N' : 'Y'), array('textCode' => 'VAT_INCLUDED', 'type' => 'checkbox', 'value' => 'N', 'skip' => $arResult['ALLOW_TAX'] ? !CCrmProductHelper::IsFieldVisible('VAT_INCLUDED', $visibleFields) ? 'Y' : 'N' : 'Y'), array('textCode' => 'SECTION', 'type' => 'select', 'value' => '0', 'items' => CCrmViewHelper::prepareSelectItemsForJS(CCrmProductHelper::PrepareSectionListItems(CCrmCatalog::EnsureDefaultExists())), 'skip' => !CCrmProductHelper::IsFieldVisible('SECTION', $visibleFields) ? 'Y' : 'N'), array('textCode' => 'SORT', 'type' => 'text', 'maxLength' => 11, 'value' => 100, 'skip' => 'Y'), array('textCode' => 'PREVIEW_PICTURE', 'type' => 'custom', 'value' => $htmlPreviewPictureValue, 'skip' => !CCrmProductHelper::IsFieldVisible('PREVIEW_PICTURE', $visibleFields) ? 'Y' : 'N'), array('textCode' => 'DETAIL_PICTURE', 'type' => 'custom', 'value' => $htmlDetailPictureValue, 'skip' => !CCrmProductHelper::IsFieldVisible('DETAIL_PICTURE', $visibleFields) ? 'Y' : 'N')), "ownerCurrencyId" => $currencyID);
unset($visibleFields);
$arResult['PRODUCT_PROPS_USER_TYPES'] = $arPropUserTypeList;
$arResult['PRODUCT_PROPS'] = $arProps;
/** @var CBitrixComponent $this */
$this->IncludeComponentTemplate();
示例#7
0
 public static function CheckFieldId($catalogID, $fieldID)
 {
     if ($fieldID === "DETAIL_PICTURE") {
         return true;
     } elseif ($fieldID === "PREVIEW_PICTURE") {
         return true;
     } elseif ($fieldID === "PICTURE") {
         return true;
     } elseif ($catalogID <= 0 || $catalogID !== CCrmCatalog::EnsureDefaultExists()) {
         return false;
     } elseif (!preg_match("/^PROPERTY_(.+)\$/", $fieldID, $match)) {
         return false;
     } else {
         $db_prop = CIBlockProperty::GetPropertyArray($match[1], $catalogID);
         if (is_array($db_prop) && $db_prop["PROPERTY_TYPE"] === "F") {
             return true;
         }
     }
     return false;
 }
 private function SaveOrderDataProducts($arOrder, $dealId)
 {
     if (!isset($arOrder["ITEMS"]) || !is_array($arOrder["ITEMS"])) {
         return false;
     }
     if (!$this->catalogId) {
         if ($this->arExternalSale == null) {
             $this->arExternalSale = CCrmExternalSale::GetDefaultSettings($this->externalSaleId);
         }
         $this->catalogId = CCrmCatalog::GetCatalogId($this->arExternalSale["NAME"], $this->externalSaleId, SITE_ID);
         if (!$this->catalogId) {
             if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
                 $this->AddError($ex->GetID(), $ex->GetString());
             } else {
                 $this->AddError("CCA", "Catalog creation error");
             }
             return false;
         }
     }
     $arProductRows = array();
     foreach ($arOrder["ITEMS"] as $arItem) {
         $productId = 0;
         $dbProduct = CCrmProduct::GetList(array(), array("CATALOG_ID" => $this->catalogId, "ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => $arItem["ID"], "CHECK_PERMISSIONS" => "N"), array('ID'), array('nTopCount' => 1));
         if ($arProduct = $dbProduct->Fetch()) {
             $productId = $arProduct["ID"];
         }
         $arFields = array('NAME' => $arItem["NAME"], 'ACTIVE' => "Y", 'CATALOG_ID' => $this->catalogId, 'PRICE' => $arItem["PRICE"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => $arItem["ID"]);
         if ($productId == 0) {
             $res = CCrmProduct::Add($arFields);
             if ($res > 0) {
                 $productId = (int) $res;
             }
         } else {
             $res = CCrmProduct::Update($productId, $arFields);
         }
         if (!$res) {
             if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
                 $this->AddError($ex->GetID(), $ex->GetString());
             } else {
                 $this->AddError("CDA", "Product creation error");
             }
             continue;
         }
         $arProductRows[] = array('PRODUCT_ID' => $productId, 'PRICE' => $arItem["PRICE"], 'QUANTITY' => $arItem["QUANTITY"]);
     }
     if (is_array($arOrder["TAXES"])) {
         foreach ($arOrder["TAXES"] as $arItem) {
             if (intval($arItem["IN_PRICE"]) > 0) {
                 continue;
             }
             $productId = 0;
             $dbProduct = CCrmProduct::GetList(array(), array("CATALOG_ID" => $this->catalogId, "ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => "tax_" . $arItem["NAME"], "CHECK_PERMISSIONS" => "N"), array('ID'), array('nTopCount' => 1));
             if ($arProduct = $dbProduct->Fetch()) {
                 $productId = $arProduct["ID"];
             }
             $arFields = array('NAME' => $arItem["NAME"], 'ACTIVE' => "Y", 'CATALOG_ID' => $this->catalogId, 'PRICE' => $arItem["PRICE"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => "tax_" . $arItem["NAME"]);
             if ($productId == 0) {
                 $res = CCrmProduct::Add($arFields);
                 $productId = intval($res);
             } else {
                 $res = CCrmProduct::Update($productId, $arFields);
             }
             if (!$res) {
                 if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
                     $this->AddError($ex->GetID(), $ex->GetString());
                 } else {
                     $this->AddError("CDA", "Product creation error");
                 }
                 continue;
             }
             $arProductRows[] = array('PRODUCT_ID' => $productId, 'PRICE' => $arItem["PRICE"], 'QUANTITY' => 1);
         }
     }
     if (is_array($arOrder["DISCOUNTS"])) {
         foreach ($arOrder["DISCOUNTS"] as $arItem) {
             if (intval($arItem["IN_PRICE"]) > 0) {
                 continue;
             }
             $productId = 0;
             $dbProduct = CCrmProduct::GetList(array(), array("CATALOG_ID" => $this->catalogId, "ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => "discount_" . $arItem["NAME"], "CHECK_PERMISSIONS" => "N"), array('ID'), array('nTopCount' => 1));
             if ($arProduct = $dbProduct->Fetch()) {
                 $productId = $arProduct["ID"];
             }
             $arFields = array('NAME' => $arItem["NAME"], 'ACTIVE' => "Y", 'CATALOG_ID' => $this->catalogId, 'PRICE' => $arItem["PRICE"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => "discount_" . $arItem["NAME"]);
             if ($productId == 0) {
                 $res = CCrmProduct::Add($arFields);
                 $productId = intval($res);
             } else {
                 $res = CCrmProduct::Update($productId, $arFields);
             }
             if (!$res) {
                 if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
                     $this->AddError($ex->GetID(), $ex->GetString());
                 } else {
                     $this->AddError("CDA", "Product creation error");
                 }
                 continue;
             }
             $arProductRows[] = array('PRODUCT_ID' => $productId, 'PRICE' => -$arItem["PRICE"], 'QUANTITY' => 1);
         }
     }
     CCrmProductRow::SaveRows("D", $dealId, $arProductRows, null, false, false);
     return true;
 }
示例#9
0
        $measureListItems[$measure['ID']] = $measure['SYMBOL'];
    }
    unset($measure);
}
unset($measures);
$productID = isset($arParams['PRODUCT_ID']) ? intval($arParams['PRODUCT_ID']) : 0;
if ($productID <= 0) {
    $productIDParName = isset($arParams['PRODUCT_ID_PAR_NAME']) ? strval($arParams['PRODUCT_ID_PAR_NAME']) : '';
    if (strlen($productIDParName) == 0) {
        $productIDParName = 'product_id';
    }
    $productID = isset($_REQUEST[$productIDParName]) ? intval($_REQUEST[$productIDParName]) : 0;
}
$arResult['PRODUCT_ID'] = $productID;
$product = $productID > 0 ? CCrmProduct::GetByID($productID, true) : false;
$arResult['CATALOG_ID'] = $catalogID = isset($product['CATALOG_ID']) ? intval($product['CATALOG_ID']) : CCrmCatalog::EnsureDefaultExists();
if (!$product) {
    ShowError(GetMessage('CRM_PRODUCT_NOT_FOUND'));
    @define('ERROR_404', 'Y');
    if ($arParams['SET_STATUS_404'] === 'Y') {
        CHTTP::SetStatus("404 Not Found");
    }
    return;
}
// Product properties
$arPropUserTypeList = CCrmProductPropsHelper::GetPropsTypesByOperations(false, 'view');
$arResult['PROP_USER_TYPES'] = $arPropUserTypeList;
$arProps = CCrmProductPropsHelper::GetProps($catalogID, $arPropUserTypeList);
$arResult['PROPS'] = $arProps;
$arResult['PRODUCT'] = $product;
$arResult['FORM_ID'] = 'CRM_PRODUCT_SHOW';
示例#10
0
 public static function GetByOriginID($originID, $catalogID = 0)
 {
     $catalogID = intval($catalogID);
     if ($catalogID <= 0) {
         $catalogID = CCrmCatalog::GetDefaultID();
     }
     if ($catalogID <= 0) {
         return false;
     }
     $dbRes = CCrmProduct::GetList(array(), array('CATALOG_ID' => $catalogID, 'ORIGIN_ID' => $originID), array('*'), array('nTopCount' => 1));
     return $dbRes->GetNext();
 }
示例#11
0
 public function Add($arFields, &$arRecalculated = false, $siteId = SITE_ID, $options = array())
 {
     /** @global \CDatabase $DB */
     global $DB;
     if (!CModule::IncludeModule('sale')) {
         return false;
     }
     if (!is_array($options)) {
         $options = array();
     }
     $bRecalculate = is_array($arRecalculated);
     $orderID = false;
     $tmpOrderId = intval($arFields['ID']) <= 0 ? 0 : $arFields['ID'];
     if (isset($arFields['ID'])) {
         unset($arFields['ID']);
     }
     $arPrevOrder = $tmpOrderId !== 0 ? CCrmInvoice::GetByID($tmpOrderId) : null;
     $userId = CCrmSecurityHelper::GetCurrentUserID();
     if (!isset($arFields['RESPONSIBLE_ID']) || (int) $arFields['RESPONSIBLE_ID'] <= 0) {
         if (is_array($arPrevOrder) && isset($arPrevOrder['RESPONSIBLE_ID']) && intval($arPrevOrder['RESPONSIBLE_ID']) > 0) {
             $arFields['RESPONSIBLE_ID'] = $arPrevOrder['RESPONSIBLE_ID'];
         } else {
             $arFields['RESPONSIBLE_ID'] = $userId;
         }
     }
     $orderStatus = '';
     if (isset($arFields['STATUS_ID'])) {
         $orderStatus = $arFields['STATUS_ID'];
         unset($arFields['STATUS_ID']);
     }
     // prepare entity permissions
     $arAttr = array();
     if (!empty($arFields['OPENED'])) {
         $arAttr['OPENED'] = $arFields['OPENED'];
     }
     $sPermission = $tmpOrderId > 0 ? 'WRITE' : 'ADD';
     if ($this->bCheckPermission) {
         $arEntityAttr = self::BuildEntityAttr($userId, $arAttr);
         $userPerms = $userId == CCrmPerms::GetCurrentUserID() ? $this->cPerms : CCrmPerms::GetUserPermissions($userId);
         $sEntityPerm = $userPerms->GetPermType('INVOICE', $sPermission, $arEntityAttr);
         if ($sEntityPerm == BX_CRM_PERM_NONE) {
             $this->LAST_ERROR = GetMessage('CRM_PERMISSION_DENIED');
             $GLOBALS['APPLICATION']->ThrowException($this->LAST_ERROR);
             return false;
         }
         $responsibleID = intval($arFields['RESPONSIBLE_ID']);
         if ($sEntityPerm == BX_CRM_PERM_SELF && $responsibleID != $userId) {
             $arFields['RESPONSIBLE_ID'] = $userId;
         }
         if ($sEntityPerm == BX_CRM_PERM_OPEN && $userId == $responsibleID) {
             $arFields['OPENED'] = 'Y';
         }
     }
     $responsibleID = intval($arFields['RESPONSIBLE_ID']);
     $arEntityAttr = self::BuildEntityAttr($responsibleID, $arAttr);
     $userPerms = $responsibleID == CCrmPerms::GetCurrentUserID() ? $this->cPerms : CCrmPerms::GetUserPermissions($responsibleID);
     $sEntityPerm = $userPerms->GetPermType('INVOICE', $sPermission, $arEntityAttr);
     $this->PrepareEntityAttrs($arEntityAttr, $sEntityPerm);
     // date fields
     if ($tmpOrderId === 0) {
         $arFields['~DATE_BILL'] = $DB->CharToDateFunction(isset($arFields['DATE_BILL']) && $arFields['DATE_BILL'] !== '' ? $arFields['DATE_BILL'] : ConvertTimeStamp(time(), 'SHORT', SITE_ID), 'SHORT', false);
     } else {
         if (isset($arFields['DATE_BILL']) && $arFields['DATE_BILL'] !== '') {
             $arFields['~DATE_BILL'] = $DB->CharToDateFunction($arFields['DATE_BILL'], 'SHORT', false);
         }
     }
     unset($arFields['DATE_BILL']);
     if (isset($arFields['DATE_PAY_BEFORE']) && $arFields['DATE_PAY_BEFORE'] !== '') {
         $arFields['~DATE_PAY_BEFORE'] = $DB->CharToDateFunction($arFields['DATE_PAY_BEFORE'], 'SHORT', false);
     }
     unset($arFields['DATE_PAY_BEFORE']);
     if ($tmpOrderId !== 0 && !isset($arFields['PRODUCT_ROWS']) && !isset($arFields['INVOICE_PROPERTIES'])) {
         if (!is_array($arPrevOrder)) {
             return false;
         }
         $prevResponsibleID = isset($arPrevOrder['RESPONSIBLE_ID']) ? intval($arPrevOrder['RESPONSIBLE_ID']) : 0;
         $responsibleID = isset($arFields['RESPONSIBLE_ID']) ? intval($arFields['RESPONSIBLE_ID']) : 0;
         $prevStatusID = isset($arPrevOrder['STATUS_ID']) ? $arPrevOrder['STATUS_ID'] : '';
         // simple update order fields
         $CSaleOrder = new CSaleOrder();
         $orderID = $CSaleOrder->Update($tmpOrderId, $arFields);
         CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => false));
         $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $tmpOrderId, $arFields);
         $registerSonetEvent = isset($options['REGISTER_SONET_EVENT']) && $options['REGISTER_SONET_EVENT'] === true;
         if (is_int($orderID) && $orderID > 0) {
             if ($registerSonetEvent) {
                 $newDealID = isset($arFields['UF_DEAL_ID']) ? intval($arFields['UF_DEAL_ID']) : 0;
                 $oldDealID = isset($arPrevOrder['UF_DEAL_ID']) ? intval($arPrevOrder['UF_DEAL_ID']) : 0;
                 $newCompanyID = isset($arFields['UF_COMPANY_ID']) ? intval($arFields['UF_COMPANY_ID']) : 0;
                 $oldCompanyID = isset($arPrevOrder['UF_COMPANY_ID']) ? intval($arPrevOrder['UF_COMPANY_ID']) : 0;
                 $newContactID = isset($arFields['UF_CONTACT_ID']) ? intval($arFields['UF_CONTACT_ID']) : 0;
                 $oldContactID = isset($arPrevOrder['UF_CONTACT_ID']) ? intval($arPrevOrder['UF_CONTACT_ID']) : 0;
                 $parents = array();
                 $parentsChanged = $newDealID !== $oldDealID || $newCompanyID !== $oldCompanyID || $newContactID !== $oldContactID;
                 if ($parentsChanged) {
                     if ($newDealID > 0) {
                         $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Deal, 'ENTITY_ID' => $newDealID);
                     }
                     if ($newCompanyID > 0) {
                         $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $newCompanyID);
                     }
                     if ($newContactID > 0) {
                         $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $newContactID);
                     }
                 }
                 $oldOrderStatus = isset($arPrevOrder['STATUS_ID']) ? $arPrevOrder['STATUS_ID'] : '';
                 self::SynchronizeLiveFeedEvent($orderID, array('PROCESS_PARENTS' => $parentsChanged, 'PARENTS' => $parents, 'REFRESH_DATE' => $orderStatus !== $oldOrderStatus, 'START_RESPONSIBLE_ID' => $prevResponsibleID, 'FINAL_RESPONSIBLE_ID' => $responsibleID, 'TOPIC' => isset($arPrevOrder['ORDER_TOPIC']) ? $arPrevOrder['ORDER_TOPIC'] : $orderID));
             }
             if ($responsibleID !== $prevResponsibleID) {
                 CCrmSonetSubscription::ReplaceSubscriptionByEntity(CCrmOwnerType::Invoice, $orderID, CCrmSonetSubscriptionType::Responsibility, $responsibleID, $prevResponsibleID, $registerSonetEvent);
             }
         }
     } else {
         // check product rows
         if (!isset($arFields['PRODUCT_ROWS']) || !is_array($arFields['PRODUCT_ROWS']) || count($arFields['PRODUCT_ROWS']) <= 0) {
             return false;
         }
         $arProduct = $arFields['PRODUCT_ROWS'];
         // prepare shopping cart data
         // <editor-fold defaultstate="collapsed" desc="prepare shopping cart data ...">
         // get xml_id fields
         $catalogXmlId = CCrmCatalog::GetDefaultCatalogXmlId();
         $arNewProducts = array();
         $bGetBasketXmlIds = false;
         foreach ($arProduct as &$productRow) {
             if (isset($productRow['ID']) && intval($productRow['ID']) === 0 && isset($productRow['PRODUCT_ID'])) {
                 $arNewProducts[] = $productRow['PRODUCT_ID'];
             } else {
                 $bGetBasketXmlIds = true;
             }
         }
         unset($productRow);
         $arXmlIds = array();
         $oldProductRows = null;
         if ($bGetBasketXmlIds && intval($tmpOrderId) > 0) {
             $oldProductRows = CCrmInvoice::GetProductRows($tmpOrderId);
             if (count($oldProductRows) > 0) {
                 foreach ($oldProductRows as $row) {
                     $arXmlIds[intval($row['ID'])][$row['PRODUCT_ID']] = array('CATALOG_XML_ID' => $row['CATALOG_XML_ID'], 'PRODUCT_XML_ID' => $row['PRODUCT_XML_ID']);
                 }
                 unset($row);
             }
         }
         unset($bGetBasketXmlIds);
         if (count($arNewProducts) > 0) {
             $dbRes = CCrmProduct::GetList(array(), array('ID' => $arNewProducts), array('ID', 'XML_ID'));
             while ($row = $dbRes->Fetch()) {
                 $arXmlIds[0][$row['ID']] = array('CATALOG_XML_ID' => $catalogXmlId, 'PRODUCT_XML_ID' => $row['XML_ID']);
             }
             unset($dbRes, $row);
         }
         unset($arNewProducts, $arOldProducts);
         // products without measures
         $productMeasures = array();
         $productId = 0;
         $productIds = array();
         foreach ($arProduct as $productRow) {
             $productId = intval($productRow['PRODUCT_ID']);
             if ($productId > 0 && (!array_key_exists('MEASURE_CODE', $productRow) || intval($productRow['MEASURE_CODE']) <= 0)) {
                 $productIds[] = $productId;
             }
         }
         unset($productId, $productRow);
         if (count($productIds) > 0) {
             $productMeasures = \Bitrix\Crm\Measure::getProductMeasures($productIds);
         }
         unset($productIds);
         $currencyId = CCrmInvoice::GetCurrencyID($siteId);
         $i = 0;
         $defaultMeasure = null;
         $oldProductRowsById = null;
         foreach ($arProduct as &$productRow) {
             $productXmlId = $catalogXmlId = null;
             $rowIndex = intval($productRow['ID']);
             $productId = $productRow['PRODUCT_ID'];
             $isCustomized = isset($productRow['CUSTOMIZED']) && $productRow['CUSTOMIZED'] === 'Y';
             $productRow['MODULE'] = $productRow['PRODUCT_PROVIDER_CLASS'] = '';
             if ($productId > 0) {
                 if (!$isCustomized) {
                     $productRow['MODULE'] = 'catalog';
                     $productRow['PRODUCT_PROVIDER_CLASS'] = 'CCatalogProductProvider';
                 }
                 if (is_array($arXmlIds[$rowIndex]) && isset($arXmlIds[$rowIndex][$productId])) {
                     $catalogXmlId = $arXmlIds[$rowIndex][$productId]['CATALOG_XML_ID'];
                     $productXmlId = $arXmlIds[$rowIndex][$productId]['PRODUCT_XML_ID'];
                 }
                 $productRow['CATALOG_XML_ID'] = $catalogXmlId;
                 $productRow['PRODUCT_XML_ID'] = $productXmlId;
             } else {
                 $productRow["PRODUCT_XML_ID"] = "CRM-" . randString(8);
                 $ri = new \Bitrix\Main\Type\RandomSequence($productRow["PRODUCT_XML_ID"]);
                 $productRow["PRODUCT_ID"] = $ri->rand(1000000, 9999999);
                 $productRow['CATALOG_XML_ID'] = '';
             }
             if ($isCustomized) {
                 $productRow['CUSTOM_PRICE'] = 'Y';
             }
             if (isset($productRow['PRODUCT_NAME'])) {
                 $productRow['NAME'] = $productRow['PRODUCT_NAME'];
                 unset($productRow['PRODUCT_NAME']);
             }
             if (isset($productRow['PRICE'])) {
                 $productRow['PRICE_DEFAULT'] = $productRow['PRICE'];
             }
             if (!isset($productRow['CURRENCY'])) {
                 $productRow['CURRENCY'] = $currencyId;
             }
             // measures
             $bRefreshMeasureName = false;
             if (!array_key_exists('MEASURE_CODE', $productRow) || intval($productRow['MEASURE_CODE'] <= 0)) {
                 if ($oldProductRows === null && $tmpOrderId > 0) {
                     $oldProductRows = CCrmInvoice::GetProductRows($tmpOrderId);
                 }
                 if (is_array($oldProductRows) && count($oldProductRows) > 0 && $oldProductRowsById === null) {
                     $oldProductRowsById = array();
                     foreach ($oldProductRows as $row) {
                         $oldProductRowsById[intval($row['ID'])] = $row;
                     }
                     unset($row);
                 }
                 if (is_array($oldProductRowsById) && isset($oldProductRowsById[$rowIndex])) {
                     $row = $oldProductRowsById[$rowIndex];
                     if (intval($productId) === intval($row['PRODUCT_ID'])) {
                         if (isset($row['MEASURE_CODE'])) {
                             $productRow['MEASURE_CODE'] = $row['MEASURE_CODE'];
                         }
                         if (isset($row['MEASURE_NAME'])) {
                             $productRow['MEASURE_NAME'] = $row['MEASURE_NAME'];
                         } else {
                             $bRefreshMeasureName = true;
                         }
                         unset($row);
                     }
                 }
             }
             if (!isset($productRow['MEASURE_CODE']) || intval($productRow['MEASURE_CODE']) <= 0) {
                 if ($productId > 0 && isset($productMeasures[$productId])) {
                     $measure = is_array($productMeasures[$productId][0]) ? $productMeasures[$productId][0] : null;
                     if (is_array($measure)) {
                         if (isset($measure['CODE'])) {
                             $productRow['MEASURE_CODE'] = $measure['CODE'];
                         }
                         if (isset($measure['SYMBOL'])) {
                             $productRow['MEASURE_NAME'] = $measure['SYMBOL'];
                         }
                     }
                     unset($measure);
                 }
             }
             if (!isset($productRow['MEASURE_CODE']) || intval($productRow['MEASURE_CODE']) <= 0) {
                 if ($defaultMeasure === null) {
                     $defaultMeasure = \Bitrix\Crm\Measure::getDefaultMeasure();
                 }
                 if (is_array($defaultMeasure)) {
                     $productRow['MEASURE_CODE'] = $defaultMeasure['CODE'];
                     $productRow['MEASURE_NAME'] = $defaultMeasure['SYMBOL'];
                 }
             }
             if (isset($productRow['MEASURE_CODE']) && intval($productRow['MEASURE_CODE']) > 0 && ($bRefreshMeasureName || !array_key_exists('MEASURE_NAME', $productRow) || empty($productRow['MEASURE_NAME']))) {
                 $measure = \Bitrix\Crm\Measure::getMeasureByCode($productRow['MEASURE_CODE']);
                 if (is_array($measure) && isset($measure['SYMBOL'])) {
                     $productRow['MEASURE_NAME'] = $measure['SYMBOL'];
                 }
                 unset($measure);
             }
             $i++;
         }
         unset($productRow, $productMeasures, $catalogXmlId, $productXmlId);
         $arOrderProductPrice = self::__fGetUserShoppingCart($arProduct, $siteId, 'N');
         foreach ($arOrderProductPrice as &$arItem) {
             $arItem["ID_TMP"] = $arItem["ID"];
             $arItem["NAME_TMP"] = $arItem["NAME"];
             unset($arItem["ID"]);
         }
         unset($arItem);
         // user id for order
         $saleUserId = intval(CSaleUser::GetAnonymousUserID());
         if ($saleUserId <= 0) {
             return false;
         }
         $arErrors = array();
         $arShoppingCart = CSaleBasket::DoGetUserShoppingCart($siteId, $saleUserId, $arOrderProductPrice, $arErrors, array(), $tmpOrderId);
         if (!is_array($arShoppingCart) || count($arShoppingCart) === 0) {
             $GLOBALS['APPLICATION']->ThrowException(GetMessage('CRM_ERROR_EMPTY_INVOICE_SPEC'));
             return false;
         }
         foreach ($arShoppingCart as $key => &$arItem) {
             $arItem["ID"] = $arItem["ID_TMP"];
             $arItem["NAME"] = $arItem["NAME_TMP"];
             unset($arItem["NAME_TMP"], $arItem["ID_TMP"]);
             //$arShoppingCart[$key]["ID"] = $arItem["ID"];
         }
         unset($key, $arItem);
         // </editor-fold>
         // person type
         $personTypeId = 0;
         if (!isset($arFields['PERSON_TYPE_ID']) || intval($arFields['PERSON_TYPE_ID']) <= 0) {
             $arPersonTypes = CCrmPaySystem::getPersonTypeIDs();
             if (isset($arPersonTypes['CONTACT'])) {
                 $personTypeId = intval($arPersonTypes['CONTACT']);
             }
         } else {
             $personTypeId = $arFields['PERSON_TYPE_ID'];
         }
         if ($personTypeId <= 0) {
             return false;
         }
         // preparing order to save
         // <editor-fold defaultstate="collapsed" desc="preparing order to save ...">
         $arOrderPropsValues = array();
         if (isset($arFields['INVOICE_PROPERTIES']) && is_array($arFields['INVOICE_PROPERTIES']) && count($arFields['INVOICE_PROPERTIES']) > 0) {
             $arOrderPropsValues = $arFields['INVOICE_PROPERTIES'];
         }
         if (isset($arFields['INVOICE_PROPERTIES'])) {
             unset($arFields['INVOICE_PROPERTIES']);
         }
         if (count($arOrderPropsValues) <= 0) {
             return false;
         }
         $deliveryId = null;
         $paySystemId = $arFields['PAY_SYSTEM_ID'];
         $arOptions = array('LOCATION_IN_CODES' => true);
         // let DoCalculateOrder know we send location in CODEs
         $arErrors = $arWarnings = array();
         $CSaleOrder = new CSaleOrder();
         $arOrder = $CSaleOrder->DoCalculateOrder($siteId, $saleUserId, $arShoppingCart, $personTypeId, $arOrderPropsValues, $deliveryId, $paySystemId, $arOptions, $arErrors, $arWarnings);
         if (count($arOrder) <= 0) {
             return false;
         }
         // </editor-fold>
         if ($bRecalculate) {
             foreach ($arOrder as $k => $v) {
                 $arRecalculated[$k] = $v;
             }
             return true;
         }
         // merge order fields
         $arAdditionalFields = array();
         foreach ($arFields as $k => $v) {
             if ($k === 'PRODUCT_ROWS') {
                 continue;
             }
             $arAdditionalFields[$k] = $v;
         }
         $arOrder['LOCATION_IN_CODES'] = true;
         // let DoSaveOrder know we send location in IDs
         // saving order
         $arErrors = array();
         $orderID = $CSaleOrder->DoSaveOrder($arOrder, $arAdditionalFields, $tmpOrderId, $arErrors);
         if (is_int($orderID) && $orderID > 0) {
             CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => $tmpOrderId === 0));
             $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $orderID, $arFields);
         }
         if (is_int($orderID) && $orderID > 0 && isset($options['REGISTER_SONET_EVENT']) && $options['REGISTER_SONET_EVENT'] === true) {
             $prevResponsibleID = is_array($arPrevOrder) && isset($arPrevOrder['RESPONSIBLE_ID']) ? intval($arPrevOrder['RESPONSIBLE_ID']) : 0;
             $responsibleID = isset($arFields['RESPONSIBLE_ID']) ? intval($arFields['RESPONSIBLE_ID']) : 0;
             if ($tmpOrderId <= 0) {
                 self::RegisterLiveFeedEvent($arFields, $orderID, $userId);
                 if ($responsibleID > 0) {
                     CCrmSonetSubscription::RegisterSubscription(CCrmOwnerType::Invoice, $orderID, CCrmSonetSubscriptionType::Responsibility, $responsibleID);
                 }
             } else {
                 $newDealID = isset($arFields['UF_DEAL_ID']) ? intval($arFields['UF_DEAL_ID']) : 0;
                 $oldDealID = isset($arPrevOrder['UF_DEAL_ID']) ? intval($arPrevOrder['UF_DEAL_ID']) : 0;
                 $newCompanyID = isset($arFields['UF_COMPANY_ID']) ? intval($arFields['UF_COMPANY_ID']) : 0;
                 $oldCompanyID = isset($arPrevOrder['UF_COMPANY_ID']) ? intval($arPrevOrder['UF_COMPANY_ID']) : 0;
                 $newContactID = isset($arFields['UF_CONTACT_ID']) ? intval($arFields['UF_CONTACT_ID']) : 0;
                 $oldContactID = isset($arPrevOrder['UF_CONTACT_ID']) ? intval($arPrevOrder['UF_CONTACT_ID']) : 0;
                 $parents = array();
                 $parentsChanged = $newDealID !== $oldDealID || $newCompanyID !== $oldCompanyID || $newContactID !== $oldContactID;
                 if ($parentsChanged) {
                     if ($newDealID > 0) {
                         $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Deal, 'ENTITY_ID' => $newDealID);
                     }
                     if ($newCompanyID > 0) {
                         $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $newCompanyID);
                     }
                     if ($newContactID > 0) {
                         $parents[] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $newContactID);
                     }
                 }
                 $oldOrderStatus = isset($arPrevOrder['STATUS_ID']) ? $arPrevOrder['STATUS_ID'] : '';
                 self::SynchronizeLiveFeedEvent($orderID, array('PROCESS_PARENTS' => $parentsChanged, 'PARENTS' => $parents, 'REFRESH_DATE' => $orderStatus !== $oldOrderStatus, 'START_RESPONSIBLE_ID' => $prevResponsibleID, 'FINAL_RESPONSIBLE_ID' => $responsibleID, 'TOPIC' => isset($arPrevOrder['ORDER_TOPIC']) ? $arPrevOrder['ORDER_TOPIC'] : $orderID));
                 if ($responsibleID !== $prevResponsibleID) {
                     CCrmSonetSubscription::ReplaceSubscriptionByEntity(CCrmOwnerType::Invoice, $orderID, CCrmSonetSubscriptionType::Responsibility, $responsibleID, $prevResponsibleID, true);
                 }
             }
         }
     }
     if (intval($orderID) > 0 && !empty($orderStatus)) {
         // set status
         $this->SetStatus($orderID, $orderStatus);
         // update entity permissions
         CCrmPerms::UpdateEntityAttr('INVOICE', $orderID, $arEntityAttr);
         $newDealID = isset($arFields['UF_DEAL_ID']) ? (int) $arFields['UF_DEAL_ID'] : 0;
         $oldDealID = is_array($arPrevOrder) && isset($arPrevOrder['UF_DEAL_ID']) ? (int) $arPrevOrder['UF_DEAL_ID'] : 0;
         if ($newDealID) {
             Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::register($newDealID);
         }
         if ($oldDealID > 0 && $oldDealID !== $newDealID) {
             Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::register($oldDealID);
         }
         if (isset($options['UPDATE_SEARCH']) && $options['UPDATE_SEARCH'] === true) {
             $arFilterTmp = array('ID' => $orderID);
             if (!$this->bCheckPermission) {
                 $arFilterTmp["CHECK_PERMISSIONS"] = "N";
             }
             CCrmSearch::UpdateSearch($arFilterTmp, 'INVOICE', true);
         }
     }
     return $orderID;
 }
示例#12
0
    if (in_array($k, $arStrFilters, true)) {
        $arFilter['?' . $k] = $v;
        unset($arFilter[$k]);
    }
}
$arSort = array();
$by = isset($_GET['by']) ? trim($_GET['by']) : 'ID';
$sort = isset($_GET['order']) ? trim($_GET['order']) : 'asc';
if (isset($_GET['by']) && isset($_GET['order'])) {
    $arSort = array($by => $sort);
}
$gridSorting = $CGridOptions->GetSorting(array('sort' => array('sort' => 'asc'), 'vars' => array('by' => 'by', 'order' => 'order')));
$arResult['SORT'] = !empty($arSort) ? $arSort : $gridSorting['sort'];
$arResult['SORT_VARS'] = $gridSorting['vars'];
$arOrder = strtoupper($by) === 'ID' ? array($by => $sort) : array($by => $sort, 'ID' => 'ASC');
$arFilter['IBLOCK_ID'] = intval(CCrmCatalog::EnsureDefaultExists());
$arFilter['CHECK_PERMISSIONS'] = 'N';
$arFilter['!PROPERTY_TYPE'] = 'G';
$errorMsg = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && check_bitrix_sessid() && isset($_POST['action_button_' . $arResult['GRID_ID']])) {
    $action = $_POST['action_button_' . $arResult['GRID_ID']];
    if ($arResult['CAN_EDIT'] && $action === 'edit') {
        foreach ($_POST['FIELDS'] as $id => $arFields) {
            $DB->StartTransaction();
            $id = IntVal($id);
            $arFields["USER_TYPE"] = "";
            if (strpos($arFields["PROPERTY_TYPE"], ":")) {
                list($arFields["PROPERTY_TYPE"], $arFields["USER_TYPE"]) = explode(':', $arFields["PROPERTY_TYPE"], 2);
            }
            $allowedFields = array('ACTIVE', 'CODE', 'FILTRABLE', 'HINT', 'IS_REQUIRED', 'MULTIPLE', 'NAME', 'SEARCHABLE', 'SORT', 'WITH_DESCRIPTION', 'XML_ID');
            $freshFields = array();
示例#13
0
    ShowError(GetMessage('CRM_IBLOCK_MODULE_NOT_INSTALLED'));
    return;
}
global $USER, $APPLICATION;
$arParams['PATH_TO_PRODUCTPROPS_LIST'] = CrmCheckPath('PATH_TO_PRODUCTPROPS_LIST', $arParams['PATH_TO_PRODUCTPROPS_LIST'], '');
$arParams['PATH_TO_PRODUCTPROPS_ADD'] = CrmCheckPath('PATH_TO_PRODUCTPROPS_ADD', $arParams['PATH_TO_PRODUCTPROPS_ADD'], '?add');
$arParams['PATH_TO_PRODUCTPROPS_EDIT'] = CrmCheckPath('PATH_TO_PRODUCTPROPS_EDIT', $arParams['PATH_TO_PRODUCTPROPS_EDIT'], '?prop_id=#prop_id#&edit');
if (!isset($arParams['TYPE'])) {
    $arParams['TYPE'] = 'list';
}
$arResult['BUTTONS'] = array();
$propID = isset($arParams['PROP_ID']) ? intval($arParams['PROP_ID']) : 0;
$CrmPerms = new CCrmPerms($USER->GetID());
$propAdd = $CrmPerms->HavePerm('CONFIG', BX_CRM_PERM_CONFIG, 'WRITE');
$arProp = null;
if ($propID > 0) {
    $iblockID = intval(CCrmCatalog::EnsureDefaultExists());
    $dbRes = CIBlockProperty::GetByID($propID, $iblockID);
    if (is_object($dbRes)) {
        $arProp = $dbRes->Fetch();
    }
    unset($dbRes);
}
$exists = intval($propID > 0) && is_array($arProp);
if ($arParams['TYPE'] !== 'list') {
    $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_PRODUCTPROP_LIST'), 'TITLE' => GetMessage('CRM_PRODUCTPROP_LIST_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_PRODUCTPROPS_LIST'], array()), 'ICON' => 'btn-list');
}
if ($arParams['TYPE'] === 'list' && $propAdd) {
    $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_PRODUCTPROP_ADD'), 'TITLE' => GetMessage('CRM_PRODUCTPROP_ADD_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_PRODUCTPROPS_ADD'], array()), 'ICON' => 'btn-new');
}
$this->IncludeComponentTemplate();
示例#14
0
    $basePriceId = CCatalogGroup::Add($arFields);
    if ($basePriceId <= 0) {
        $errMsg[] = Loc::getMessage('CRM_UPDATE_ERR_003');
        return;
    }
}
if ($basePriceId <= 0 && isset($basePrice['ID']) && $basePrice['ID'] > 0) {
    $basePriceId = $basePrice['ID'];
}
unset($basePrice, $dbRes);
$arCatalogId = array();
$dbCatalogList = CCrmCatalog::GetList();
while ($arCatalog = $dbCatalogList->Fetch()) {
    $arCatalogId[] = $arCatalog['ID'];
}
$defCatalogId = CCrmCatalog::EnsureDefaultExists();
if ($defCatalogId > 0) {
    if (!in_array($defCatalogId, $arCatalogId)) {
        $arCatalogId[] = $defCatalogId;
    }
} else {
    $errMsg[] = Loc::getMessage('CRM_UPDATE_ERR_001');
    return;
}
if (!empty($arCatalogId) && empty($errMsg)) {
    $CCatalog = new CCatalog();
    if ($CCatalog) {
        foreach ($arCatalogId as $catalogId) {
            $arFields = array('IBLOCK_ID' => $catalogId, 'CATALOG' => 'Y');
            if ($defCatVatId > 0) {
                $arFields['VAT_ID'] = $defCatVatId;
示例#15
0
 public static function processEvent(array $arParams, array $arHandler)
 {
     $eventName = $arHandler['EVENT_NAME'];
     switch (strtolower($eventName)) {
         case 'oncrmproductadd':
         case 'oncrmproductupdate':
             $ID = isset($arParams[0]) ? (int) $arParams[0] : 0;
             if ($ID <= 0) {
                 throw new RestException("Could not find entity ID in fields of event \"{$eventName}\"");
             }
             $fields = CCrmProduct::GetByID($ID);
             $catalogID = is_array($fields) && isset($fields['CATALOG_ID']) ? (int) $fields['CATALOG_ID'] : 0;
             if ($catalogID !== CCrmCatalog::GetDefaultID()) {
                 throw new RestException("Outside CRM product event is detected");
             }
             return array('FIELDS' => array('ID' => $ID));
             break;
         case 'oncrmproductdelete':
             $fields = isset($arParams[0]) && is_array($arParams[0]) ? $arParams[0] : array();
             $ID = isset($fields['ID']) ? (int) $fields['ID'] : 0;
             if ($ID <= 0) {
                 throw new RestException("Could not find entity ID in fields of event \"{$eventName}\"");
             }
             $catalogID = isset($fields['IBLOCK_ID']) ? (int) $fields['IBLOCK_ID'] : 0;
             if ($catalogID !== CCrmCatalog::GetDefaultID()) {
                 throw new RestException("Outside CRM product event is detected");
             }
             return array('FIELDS' => array('ID' => $ID));
             break;
         default:
             throw new RestException("The Event \"{$eventName}\" is not supported in current context");
     }
 }
示例#16
0
<?php

if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) {
    die;
}
if (!CModule::IncludeModule('crm') || !CModule::IncludeModule('iblock')) {
    return false;
}
global $APPLICATION;
$arCatalogs = array();
$arCatalogs['0'] = GetMessage('CRM_CATALOG_NOT_SELECTED');
$rsCatalogs = CCrmCatalog::GetList(array('NAME' => 'ASC'), array('ACTIVE' => 'Y'), array('ID', 'NAME'));
while ($arCatalog = $rsCatalogs->Fetch()) {
    $catalogID = $arCatalog['ID'];
    $arCatalogs[$catalogID] = '[' . $catalogID . '] ' . $arCatalog['NAME'];
}
$arSections = array();
$catalogID = isset($arCurrentValues['CATALOG_ID']) ? intval($arCurrentValues['CATALOG_ID']) : 0;
if ($catalogID > 0) {
    $arSections[''] = GetMessage('CRM_SECTION_NOT_SELECTED');
    $rsSections = CIBlockSection::GetList(array('left_margin' => 'asc'), array('IBLOCK_ID' => $catalogID, 'GLOBAL_ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N'), false, array('ID', 'NAME', 'DEPTH_LEVEL'));
    while ($arSection = $rsSections->GetNext()) {
        $sectionID = $arSection['ID'];
        $arSections[$sectionID] = str_repeat(' . ', $arSection['DEPTH_LEVEL']) . '[' . $sectionID . '] ' . $arSection['NAME'];
    }
}
$arComponentParameters = array('PARAMETERS' => array('SECTION_COUNT' => array('PARENT' => 'BASE', 'NAME' => GetMessage('CRM_SECTION_COUNT'), 'TYPE' => 'STRING', 'DEFAULT' => '20'), 'CATALOG_ID' => array('PARENT' => 'BASE', 'NAME' => GetMessage('CRM_CATALOG_ID'), 'TYPE' => 'LIST', 'VALUES' => $arCatalogs, 'REFRESH' => 'Y'), 'SECTION_ID' => array('PARENT' => 'BASE', 'NAME' => GetMessage('CRM_PARENT_SECTION_ID'), 'TYPE' => 'LIST', 'VALUES' => $arSections), 'SECTION_ID_PARAM' => array('PARENT' => 'BASE', 'NAME' => GetMessage('CRM_SECTION_ID_PARAM'), 'TYPE' => 'STRING', 'DEFAULT' => 'section_id'), 'PATH_TO_SECTION_LIST' => array('PARENT' => 'BASE', 'NAME' => GetMessage('CRM_PATH_TO_SECTION_LIST'), 'TYPE' => 'STRING', 'DEFAULT' => '?section_id=#section_id#&sections')));
示例#17
0
 public static function OnIBlockDelete($ID)
 {
     return CCrmCatalog::Delete($ID);
 }
示例#18
0
 public static function formatResultValue($k, &$v, &$row, &$cInfo, $total, &$customChartValue = null)
 {
     // HACK: detect if 'report.view' component is rendering excel spreadsheet
     $isHtml = !(isset($_GET['EXCEL']) && $_GET['EXCEL'] === 'Y');
     $field = $cInfo['field'];
     $fieldName = isset($cInfo['fieldName']) ? $cInfo['fieldName'] : $field->GetName();
     $prcnt = isset($cInfo['prcnt']) ? $cInfo['prcnt'] : '';
     if (!isset($prcnt[0]) && ($fieldName === 'DEAL_OWNER.OPPORTUNITY' || $fieldName === 'DEAL_OWNER.OPPORTUNITY_ACCOUNT' || $fieldName === 'DEAL_OWNER.RECEIVED_AMOUNT' || $fieldName === 'DEAL_OWNER.LOST_AMOUNT' || $fieldName === 'SUM_ACCOUNT' || $fieldName === 'PRICE_ACCOUNT' || $fieldName === 'DEAL_OWNER.COMPANY_BY.REVENUE')) {
         // unformatted value for charts
         $customChartValue['exist'] = true;
         $customChartValue['type'] = 'float';
         $customChartValue['value'] = doubleval($v);
         $v = self::MoneyToString(doubleval($v));
     } elseif ($fieldName === 'DEAL_OWNER.TITLE') {
         if ($isHtml && strlen($v) > 0 && self::$CURRENT_RESULT_ROW && isset(self::$CURRENT_RESULT_ROW['ID'])) {
             $v = self::prepareDealTitleHtml(self::$CURRENT_RESULT_ROW['ID'], $v);
         }
     } elseif ($fieldName === 'DEAL_OWNER.STAGE_ID') {
         if ($v !== '') {
             $v = self::getDealStageName($v, $isHtml);
         }
     } elseif ($fieldName === 'DEAL_OWNER.TYPE_ID') {
         if ($v !== '') {
             $v = self::getDealTypeName($v, $isHtml);
         }
     } elseif ($fieldName === 'DEAL_OWNER.CURRENCY_ID' || $fieldName === 'DEAL_OWNER.COMPANY_BY.CURRENCY_ID') {
         if ($v !== '') {
             $v = self::getCurrencyName($v, $isHtml);
         }
     } elseif ($fieldName === 'DEAL_OWNER.EVENT_ID') {
         if ($v !== '') {
             $v = self::getEventTypeName($v, $isHtml);
         }
     } elseif ($fieldName === 'DEAL_OWNER.ORIGINATOR_BY.ID') {
         $v = self::getDealOriginatorName($v, $isHtml);
     } elseif ($fieldName === 'DEAL_OWNER.CONTACT_BY.SOURCE_BY.STATUS_ID') {
         if ($v !== '') {
             $v = self::getStatusName($v, 'SOURCE', $isHtml);
         }
     } elseif (strpos($fieldName, 'DEAL_OWNER.COMPANY_BY.') === 0) {
         if (strlen($v) === 0 || trim($v) === '.') {
             if (strpos($fieldName, 'DEAL_OWNER.COMPANY_BY.COMPANY_TYPE_BY') !== 0 && strpos($fieldName, 'DEAL_OWNER.COMPANY_BY.INDUSTRY_BY') !== 0 && strpos($fieldName, 'DEAL_OWNER.COMPANY_BY.EMPLOYEES_BY') !== 0) {
                 $v = GetMessage('CRM_DEAL_COMPANY_NOT_ASSIGNED');
             }
         } elseif ($fieldName === 'DEAL_OWNER.COMPANY_BY.TITLE') {
             if ($isHtml && self::$CURRENT_RESULT_ROW && isset(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_DEAL_OWNER_COMPANY_BY_ID'])) {
                 $v = self::prepareCompanyTitleHtml(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_DEAL_OWNER_COMPANY_BY_ID'], $v);
             }
         } elseif ($fieldName === 'DEAL_OWNER.COMPANY_BY.COMPANY_TYPE_BY.STATUS_ID') {
             if ($v !== '') {
                 $v = self::getStatusName($v, 'COMPANY_TYPE', $isHtml);
             }
         } elseif ($fieldName === 'DEAL_OWNER.COMPANY_BY.INDUSTRY_BY.STATUS_ID') {
             if ($v !== '') {
                 $v = self::getStatusName($v, 'INDUSTRY', $isHtml);
             }
         } elseif ($fieldName === 'DEAL_OWNER.COMPANY_BY.EMPLOYEES_BY.STATUS_ID') {
             if ($v !== '') {
                 $v = self::getStatusName($v, 'EMPLOYEES', $isHtml);
             }
         }
     } elseif (strpos($fieldName, 'DEAL_OWNER.CONTACT_BY.') === 0) {
         if ($v === '' || trim($v) === '.') {
             if (strpos($fieldName, 'DEAL_OWNER.CONTACT_BY.TYPE_BY') !== 0) {
                 $v = GetMessage('CRM_DEAL_CONTACT_NOT_ASSIGNED');
             }
         } elseif ($fieldName === 'DEAL_OWNER.CONTACT_BY.TYPE_BY.STATUS_ID') {
             if ($v !== '') {
                 $v = self::getStatusName($v, 'CONTACT_TYPE', $isHtml);
             }
         } elseif ($fieldName === 'DEAL_OWNER.CONTACT_BY.NAME' || $fieldName === 'DEAL_OWNER.CONTACT_BY.LAST_NAME' || $fieldName === 'DEAL_OWNER.CONTACT_BY.SECOND_NAME' || $fieldName === 'DEAL_OWNER.CONTACT_BY.ADDRESS') {
             if ($isHtml && self::$CURRENT_RESULT_ROW && isset(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_DEAL_OWNER_CONTACT_BY_ID'])) {
                 $v = self::prepareContactTitleHtml(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_DEAL_OWNER_CONTACT_BY_ID'], $v);
             }
         }
     } elseif (strpos($fieldName, 'DEAL_OWNER.ASSIGNED_BY.') === 0) {
         // unset HREF for empty value
         if (empty($v) || trim($v) === '.' || $v === '&nbsp;') {
             unset($row['__HREF_' . $k]);
         }
         if (strlen($v) === 0 || trim($v) === '.') {
             $v = GetMessage('CRM_DEAL_RESPONSIBLE_NOT_ASSIGNED');
         } elseif ($isHtml) {
             $v = htmlspecialcharsbx($v);
         }
     } elseif (strpos($fieldName, 'IBLOCK_ELEMENT.') === 0) {
         static $defaultCatalogID;
         if (!isset($defaultCatalogID)) {
             $defaultCatalogID = CCrmCatalog::GetDefaultID();
         }
         if ($isHtml) {
             if ($defaultCatalogID > 0 && self::$CURRENT_RESULT_ROW) {
                 $iblockID = isset(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_IBLOCK_ELEMENT_IBLOCK_ID']) ? intval(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_IBLOCK_ELEMENT_IBLOCK_ID']) : 0;
                 $iblockElementID = isset(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_IBLOCK_ELEMENT_ID']) ? intval(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_IBLOCK_ELEMENT_ID']) : 0;
             } else {
                 $iblockID = 0;
                 $iblockElementID = 0;
             }
             if ($iblockElementID > 0 && $iblockID === $defaultCatalogID) {
                 $v = self::prepareProductNameHtml($iblockElementID, $v);
             } else {
                 $v = htmlspecialcharsbx($v);
             }
         }
     } else {
         parent::formatResultValue($k, $v, $row, $cInfo, $total);
     }
 }
示例#19
0
global $APPLICATION, $USER;
$CrmPerms = new CCrmPerms($USER->GetID());
if (!$CrmPerms->HavePerm('CONFIG', BX_CRM_PERM_CONFIG, 'WRITE')) {
    ShowError(GetMessage('CRM_PERMISSION_DENIED'));
    return;
}
$arResult['PATH_TO_EXCH1C_INDEX'] = CrmCheckPath('PATH_TO_EXCH1C_INDEX', $arParams['PATH_TO_EXCH1C_INDEX'], $APPLICATION->GetCurPage());
$arResult['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array("#NOBR#", "#/NOBR#"), array("", ""), $arParams["NAME_TEMPLATE"]);
$arResult['BACK_URL'] = $arParams['PATH_TO_EXCH1C_INDEX'];
$arResult['FORM_ID'] = 'CRM_EXCH1C_CONFIG';
$arResult['FIELDS'] = array();
// <editor-fold defaultstate="collapsed" desc="Invoice export options">
// --> Invoice export options
$arUGroupsEx = array();
$arAction = array("N" => GetMessage("CAT_1C_NONE"), "A" => GetMessage("CAT_1C_DEACTIVATE"), "D" => GetMessage("CAT_1C_DELETE"));
$iblockType = CCrmCatalog::GetCatalogTypeID();
$arStatuses = array("" => GetMessage("SALE_1C_NO"));
foreach (CCrmStatus::GetStatusList('INVOICE_STATUS') as $k => $v) {
    $arStatuses[$k] = '[' . $k . '] ' . $v;
}
$arAllOptions = array(array("1C_SALE_SITE_LIST", GetMessage("SALE_1C_SITE_LIST"), SITE_ID, array("text", 2), "hidden", 1), array("1C_SALE_ACCOUNT_NUMBER_SHOP_PREFIX", GetMessage("SALE_1C_SALE_ACCOUNT_NUMBER_SHOP_PREFIX"), "CRM_", array("text"), "visible", 1), array("1C_EXPORT_PAYED_ORDERS", GetMessage("SALE_1C_EXPORT_PAYED_ORDERS"), "", array("checkbox"), "hidden", 1), array("1C_EXPORT_ALLOW_DELIVERY_ORDERS", GetMessage("SALE_1C_EXPORT_ALLOW_DELIVERY_ORDERS"), "", array("checkbox"), "hidden", 1), array("1C_EXPORT_FINAL_ORDERS", GetMessage("SALE_1C_EXPORT_FINAL_ORDERS"), "", array("list", $arStatuses), "visible", 1), array("1C_FINAL_STATUS_ON_DELIVERY", GetMessage("SALE_1C_FINAL_STATUS_ON_DELIVERY"), "", array("list", $arStatuses), "visible", 1), array("1C_REPLACE_CURRENCY", GetMessage("SALE_1C_REPLACE_CURRENCY"), GetMessage("SALE_1C_RUB"), array("text"), "visible", 1), array("1C_SALE_GROUP_PERMISSIONS", GetMessage("SALE_1C_GROUP_PERMISSIONS"), "-", array("mlist", 5, $arUGroupsEx), "hidden", 1), array("1C_SALE_USE_ZIP", GetMessage("SALE_1C_USE_ZIP"), "Y", array("checkbox"), "hidden", 1));
$arPersonTypes = CCrmPaySystem::getPersonTypeIDs();
$tabNames = array(1 => 'tab_invoice_export', 2 => 'tab_invoice_prof_com', 3 => 'tab_invoice_prof_con');
$personTypeTabNumbers = array($arPersonTypes['COMPANY'] => 2, $arPersonTypes['CONTACT'] => 3);
$arAgent = array("CONTACT" => array("SURNAME" => GetMessage("SOG_SURNAME"), "NAME" => GetMessage("SOG_NAME"), "SECOND_NAME" => GetMessage("SOG_SECOND_NAME"), "BIRTHDAY" => GetMessage("SOG_BIRTHDAY"), "MALE" => GetMessage("SOG_MALE"), "INN" => GetMessage("SOG_INN"), "KPP" => GetMessage("SOG_KPP"), "ADDRESS_FULL" => GetMessage("SOG_ADDRESS_FULL"), "INDEX" => GetMessage("SOG_INDEX"), "COUNTRY" => GetMessage("SOG_COUNTRY"), "REGION" => GetMessage("SOG_REGION"), "STATE" => GetMessage("SOG_STATE"), "TOWN" => GetMessage("SOG_TOWN"), "CITY" => GetMessage("SOG_CITY"), "STREET" => GetMessage("SOG_STREET"), "BUILDING" => GetMessage("SOG_BUILDING"), "HOUSE" => GetMessage("SOG_HOUSE"), "FLAT" => GetMessage("SOG_FLAT")), "COMPANY" => array("ADDRESS_FULL" => GetMessage("SOG_ADDRESS_FULL"), "INDEX" => GetMessage("SOG_INDEX"), "COUNTRY" => GetMessage("SOG_COUNTRY"), "REGION" => GetMessage("SOG_REGION"), "STATE" => GetMessage("SOG_STATE"), "TOWN" => GetMessage("SOG_TOWN"), "CITY" => GetMessage("SOG_CITY"), "STREET" => GetMessage("SOG_STREET"), "BUILDING" => GetMessage("SOG_BUILDING"), "HOUSE" => GetMessage("SOG_HOUSE"), "FLAT" => GetMessage("SOG_FLAT"), "INN" => GetMessage("SOG_INN"), "KPP" => GetMessage("SOG_KPP"), "EGRPO" => GetMessage("SOG_EGRPO"), "OKVED" => GetMessage("SOG_OKVED"), "OKDP" => GetMessage("SOG_OKDP"), "OKOPF" => GetMessage("SOG_OKOPF"), "OKFC" => GetMessage("SOG_OKFC"), "OKPO" => GetMessage("SOG_OKPO"), "ACCOUNT_NUMBER" => GetMessage("SOG_ACCOUNT_NUMBER"), "B_NAME" => GetMessage("SOG_B_NAME"), "B_BIK" => GetMessage("SOG_B_BIK"), "B_ADDRESS_FULL" => GetMessage("SOG_B_ADDRESS_FULL"), "B_INDEX" => GetMessage("SOG_B_INDEX"), "B_COUNTRY" => GetMessage("SOG_B_COUNTRY"), "B_REGION" => GetMessage("SOG_B_REGION"), "B_STATE" => GetMessage("SOG_B_STATE"), "B_TOWN" => GetMessage("SOG_B_TOWN"), "B_CITY" => GetMessage("SOG_B_CITY"), "B_STREET" => GetMessage("SOG_B_STREET"), "B_BUILDING" => GetMessage("SOG_B_BUILDING"), "B_HOUSE" => GetMessage("SOG_B_HOUSE")));
$arAgentInfo = array();
foreach (array_keys($arPersonTypes) as $type) {
    if ($type === 'COMPANY' || $type === 'CONTACT') {
        $agentInfo = array("AGENT_NAME" => GetMessage("SOG_AGENT_NAME"), "FULL_NAME" => GetMessage("SOG_FULL_NAME"));
        foreach ($arAgent[$type] as $k => $v) {
            $agentInfo[$k] = $v;
示例#20
0
$CrmPerms = new CCrmPerms($USER->GetID());
if (!$CrmPerms->HavePerm('CONFIG', BX_CRM_PERM_CONFIG, 'WRITE')) {
    ShowError(GetMessage('CRM_PERMISSION_DENIED'));
    return;
}
$arResult['PATH_TO_EXCH1C_INDEX'] = CrmCheckPath('PATH_TO_EXCH1C_INDEX', $arParams['PATH_TO_EXCH1C_INDEX'], $APPLICATION->GetCurPage());
$arResult['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array("#NOBR#", "#/NOBR#"), array("", ""), $arParams["NAME_TEMPLATE"]);
$arResult['BACK_URL'] = $arParams['PATH_TO_EXCH1C_INDEX'];
$arResult['FORM_ID'] = 'CRM_EXCH1C_CONFIG';
$arResult['FIELDS'] = array();
// <editor-fold defaultstate="collapsed" desc="Catalog import options">
// --> Catalog import options
$arUGroupsEx = array();
$arAction = array("N" => GetMessage("CAT_1C_NONE"), "A" => GetMessage("CAT_1C_DEACTIVATE"), "D" => GetMessage("CAT_1C_DELETE"));
$iblockType = CCrmCatalog::GetCatalogTypeID();
$iblockId = CCrmCatalog::EnsureDefaultExists();
$arPriceType = array();
$arGroup = array();
$rsGroup = CCatalogGroup::GetListEx(array('SORT', 'ASC'), array(), false, false, array('ID', 'NAME', 'NAME_LANG', 'XML_ID'));
while ($arGroup = $rsGroup->Fetch()) {
    $arPriceType[intval($arGroup['ID'])] = '[' . $arGroup['ID'] . '] ' . $arGroup['NAME'] . (empty($arGroup['NAME_LANG']) ? '' : ', ' . $arGroup['NAME_LANG']);
}
unset($arGroup, $rsGroup);
$priceTypeId = intval(COption::GetOptionInt('crm', 'selected_catalog_group_id', 0));
if ($priceTypeId < 1) {
    $arBaseCatalogGroup = CCatalogGroup::GetBaseGroup();
    $priceTypeId = intval($arBaseCatalogGroup['ID']);
    unset($arBaseCatalogGroup);
}
$arAllOptions = array(array("1C_IBLOCK_TYPE", GetMessage("CAT_1C_IBLOCK_TYPE"), $iblockType, array("text", 50), "hidden", 1), array("1C_SITE_LIST", GetMessage("CAT_1C_SITE_LIST"), SITE_ID, array("text", 2), "hidden", 1), array("1C_INTERVAL", GetMessage("CAT_1C_INTERVAL"), "30", array("text", 20), "visible", 1), array("1C_GROUP_PERMISSIONS", GetMessage("CAT_1C_GROUP_PERMISSIONS"), "-", array("mlist", 5, $arUGroupsEx), "hidden", 1), array("1C_ELEMENT_ACTION", GetMessage("CAT_1C_ELEMENT_ACTION"), "D", array("list", $arAction), "visible", 1), array("1C_SECTION_ACTION", GetMessage("CAT_1C_SECTION_ACTION"), "D", array("list", $arAction), "visible", 1), array("1C_FILE_SIZE_LIMIT", GetMessage("CAT_1C_FILE_SIZE_LIMIT"), 200 * 1024, array("text", 20), "hidden", 1), array("1C_USE_CRC", GetMessage("CAT_1C_USE_CRC"), "Y", array("checkbox"), "hidden", 1), array("1C_USE_ZIP", GetMessage("CAT_1C_USE_ZIP"), "Y", array("checkbox"), "hidden", 1), array("1C_USE_IBLOCK_PICTURE_SETTINGS", GetMessage("CAT_1C_USE_IBLOCK_PICTURE_SETTINGS"), "N", array("checkbox"), "hidden", 1), array("1C_GENERATE_PREVIEW", GetMessage("CAT_1C_GENERATE_PREVIEW"), "N", array("checkbox"), "hidden", 1), array("1C_PREVIEW_WIDTH", GetMessage("CAT_1C_PREVIEW_WIDTH"), 100, array("text", 20), "hidden", 1), array("1C_PREVIEW_HEIGHT", GetMessage("CAT_1C_PREVIEW_HEIGHT"), 100, array("text", 20), "hidden", 1), array("1C_DETAIL_RESIZE", GetMessage("CAT_1C_DETAIL_RESIZE"), "N", array("checkbox"), "hidden", 1), array("1C_DETAIL_WIDTH", GetMessage("CAT_1C_DETAIL_WIDTH"), 300, array("text", 20), "hidden", 1), array("1C_DETAIL_HEIGHT", GetMessage("CAT_1C_DETAIL_HEIGHT"), 300, array("text", 20), "hidden", 1), array("1C_USE_OFFERS", GetMessage("CAT_1C_USE_OFFERS"), "N", array("checkbox"), "hidden", 1), array("1C_FORCE_OFFERS", GetMessage("CAT_1C_FORCE_OFFERS"), "N", array("checkbox"), "hidden", 1), array("1C_USE_IBLOCK_TYPE_ID", GetMessage("CAT_1C_USE_IBLOCK_TYPE_ID"), "N", array("checkbox"), "hidden", 1), array("1C_SKIP_ROOT_SECTION", GetMessage("CAT_1C_SKIP_ROOT_SECTION"), "N", array("checkbox"), "hidden", 1), array("1C_TRANSLIT_ON_ADD", GetMessage("CAT_1C_TRANSLIT_ON_ADD"), "N", array("checkbox"), "hidden", 1), array("1C_TRANSLIT_ON_UPDATE", GetMessage("CAT_1C_TRANSLIT_ON_UPDATE"), "N", array("checkbox"), "hidden", 1), array("1C_CRM_CAT_XML_ID", GetMessage("CRM_CATALOG_XML_ID"), "", array("text", 20), "visible", 1), array("selected_catalog_group_id", GetMessage("CRM_SELECTED_CATALOG_GROUP_ID"), $priceTypeId, array("list", $arPriceType), "visible", 1), array("1CE_IBLOCK_ID", GetMessage("CAT_1CE_IBLOCK_ID"), $iblockId, array("text", 50), "hidden", 2), array("1CE_ELEMENTS_PER_STEP", GetMessage("CAT_1CE_ELEMENTS_PER_STEP"), 100, array("text", 5), "visible", 2), array("1CE_INTERVAL", GetMessage("CAT_1CE_INTERVAL"), "30", array("text", 20), "visible", 2), array("1CE_GROUP_PERMISSIONS", GetMessage("CAT_1CE_GROUP_PERMISSIONS"), "-", array("mlist", 5, $arUGroupsEx), "hidden", 2), array("1CE_USE_ZIP", GetMessage("CAT_1CE_USE_ZIP"), "Y", array("checkbox"), "hidden", 2));
if ($_SERVER['REQUEST_METHOD'] == "POST" && $_POST['save'] != "" && check_bitrix_sessid()) {
示例#21
0
 public static function GetList($arOrder = array(), $arFilter = array(), $arSelectFields = array(), $arNavStartParams = false)
 {
     if (!CModule::IncludeModule('iblock')) {
         return false;
     }
     if (!is_array($arFilter)) {
         $arFilter = array();
     }
     $catalogID = isset($arFilter['CATALOG_ID']) ? intval($arFilter['CATALOG_ID']) : 0;
     if (!($catalogID > 0 && CCrmCatalog::Exists($catalogID))) {
         $catalogID = CCrmCatalog::EnsureDefaultExists();
     }
     $arFilter['CATALOG_ID'] = $catalogID;
     $section = new CIBlockSection();
     $effectiveFilter = CCrmProductSectionDbResult::MapKeys($arFilter);
     if (isset($effectiveFilter['IBLOCK_SECTION_ID'])) {
         $effectiveFilter['SECTION_ID'] = (int) $effectiveFilter['IBLOCK_SECTION_ID'];
     }
     return new CCrmProductSectionDbResult($section->GetList(CCrmProductSectionDbResult::MapKeys($arOrder), $effectiveFilter, false, CCrmProductSectionDbResult::MapValues($arSelectFields), $arNavStartParams));
 }
示例#22
0
        Header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
        if (!empty($result)) {
            echo CUtil::PhpToJSObject($result);
        }
        require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/epilog_after.php';
        die;
    }
}
$curUserPrems = CCrmPerms::GetCurrentUserPermissions();
$action = isset($_REQUEST['ACTION']) ? $_REQUEST['ACTION'] : '';
if ($action === 'GET_SECTIONS') {
    if (!$curUserPrems->HavePerm('CONFIG', BX_CRM_PERM_CONFIG, 'READ')) {
        __CrmMobileCompanyEditEndResonse(array('ERROR' => 'Access denied.'));
    }
    $catalogID = isset($_REQUEST['CATALOG_ID']) ? intval($_REQUEST['CATALOG_ID']) : 0;
    if ($catalogID <= 0 || !CCrmCatalog::Exists($catalogID)) {
        __CrmMobileCompanyEditEndResonse(array('ERROR' => 'Catalog ID is not found.'));
    }
    $filter = array('IBLOCK_ID' => $catalogID, 'GLOBAL_ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N');
    CModule::IncludeModule('iblock');
    $sectionID = isset($_REQUEST['SECTION_ID']) ? intval($_REQUEST['SECTION_ID']) : 0;
    $parentSectionID = 0;
    $sectionName = '';
    if ($sectionID > 0) {
        $dbSections = CIBlockSection::GetList(array(), array('ID' => $sectionID), false, array('ID', 'NAME', 'IBLOCK_SECTION_ID'));
        $section = $dbSections->Fetch();
        if ($section) {
            $sectionName = $section['NAME'];
            $parentSectionID = intval($section['IBLOCK_SECTION_ID']);
        }
    }
示例#23
0
// Prepare tax list
if (!$arResult['VAT_MODE']) {
    $arResult['TAX_LIST'] = CCrmInvoice::getTaxList($ownerID);
    $arResult['TAX_LIST_PERCENT_PRECISION'] = SALE_VALUE_PRECISION;
}
// Prepare sum total
$sumTotal = 0.0;
foreach ($arResult['PRODUCT_ROWS'] as $row) {
    if (!isset($row['PRICE']) || !isset($row['QUANTITY'])) {
        continue;
    }
    $sumTotal += doubleval($row['PRICE']) * intval($row['QUANTITY']);
}
$arResult['TAX_VALUE'] = isset($arParams['TAX_VALUE']) ? $arParams['TAX_VALUE'] : 0.0;
$arResult['SUM_TOTAL'] = isset($arParams['SUM_TOTAL']) ? $arParams['SUM_TOTAL'] : round($sumTotal, 2);
$arResult['TAX_VALUE_WT'] = round(doubleval($arParams['SUM_TOTAL'] - doubleval($arParams['TAX_VALUE'])), 2);
//SAVING MODE. ONSUBMIT: SAVE ALL PRODUCT ROWS ON SUBMIT, ONCHANGE: SAVE PRODUCT ROWS AFTER EVERY CHANGE (AJAX)
$arResult['SAVING_MODE'] = isset($arParams['SAVING_MODE']) ? strtoupper($arParams['SAVING_MODE']) : 'ONSUBMIT';
if ($arResult['SAVING_MODE'] != 'ONSUBMIT' && $arResult['SAVING_MODE'] != 'ONCHANGE') {
    $arResult['SAVING_MODE'] = 'ONSUBMIT';
}
$arResult['FORM_ID'] = isset($arParams['FORM_ID']) ? $arParams['FORM_ID'] : '';
$arResult['PREFIX'] = htmlspecialcharsbx($ownerID > 0 ? strtolower($ownerName) . '_' . strval($ownerID) : 'new_' . strtolower($ownerName));
$arResult['CONTAINER_CLASS'] = htmlspecialcharsbx(strtolower($ownerName) . '-product-rows');
$arResult['ROW_CLASS'] = '';
$arResult['PRODUCT_DATA_FIELD_NAME'] = isset($arParams['PRODUCT_DATA_FIELD_NAME']) ? $arParams['PRODUCT_DATA_FIELD_NAME'] : 'PRODUCT_ROW_DATA';
// crmProductCreateDialog dialog settings
$bVatMode = CCrmTax::isVatMode();
$arResult['INVOICE_PRODUCT_CREATE_DLG_SETTINGS'] = array('url' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_PRODUCT_EDIT'], array('product_id' => 0)), 'sessid' => bitrix_sessid(), 'messages' => array('dialogTitle' => GetMessage('CRM_PRODUCT_CREATE'), 'waitMessage' => GetMessage('CRM_PRODUCT_CREATE_WAIT'), 'ajaxError' => GetMessage('CRM_PRODUCT_CREATE_AJAX_ERR'), 'buttonCreateTitle' => GetMessage('CRM_BUTTON_CREATE_TITLE'), 'buttonCancelTitle' => GetMessage('CRM_BUTTON_CANCEL_TITLE'), 'NAME' => GetMessage('CRM_FIELD_NAME'), 'DESCRIPTION' => GetMessage('CRM_FIELD_DESCRIPTION'), 'ACTIVE' => GetMessage('CRM_FIELD_ACTIVE'), 'CURRENCY' => GetMessage('CRM_FIELD_CURRENCY'), 'PRICE' => GetMessage('CRM_FIELD_PRICE'), 'VAT_ID' => GetMessage('CRM_FIELD_VAT_ID'), 'VAT_INCLUDED' => GetMessage('CRM_FIELD_VAT_INCLUDED'), 'SECTION_ID' => GetMessage('CRM_FIELD_SECTION'), 'SORT' => GetMessage('CRM_FIELD_SORT')), 'fields' => array(array('textCode' => 'NAME', 'type' => 'text', 'maxLength' => 255, 'value' => '', 'skip' => 'N'), array('textCode' => 'DESCRIPTION', 'type' => 'textarea', 'maxLength' => 7500, 'value' => '', 'skip' => 'N'), array('textCode' => 'ACTIVE', 'type' => 'checkbox', 'value' => 'Y', 'skip' => 'N'), array('textCode' => 'CURRENCY', 'type' => 'select', 'value' => CCrmCurrency::GetBaseCurrencyID(), 'items' => CCrmViewHelper::prepareSelectItemsForJS(CCrmCurrencyHelper::PrepareListItems()), 'skip' => 'N'), array('textCode' => 'PRICE', 'type' => 'text', 'maxLength' => 21, 'value' => '0.00', 'skip' => 'N'), array('textCode' => 'VAT_ID', 'type' => 'select', 'value' => '', 'items' => $bVatMode ? CCrmViewHelper::prepareSelectItemsForJS(CCrmVat::GetVatRatesListItems()) : null, 'skip' => $bVatMode ? 'N' : 'Y'), array('textCode' => 'VAT_INCLUDED', 'type' => 'checkbox', 'value' => 'N', 'skip' => $bVatMode ? 'N' : 'Y'), array('textCode' => 'SECTION_ID', 'type' => 'select', 'value' => '0', 'items' => CCrmViewHelper::prepareSelectItemsForJS(CCrmProductHelper::PrepareSectionListItems(CCrmCatalog::EnsureDefaultExists())), 'skip' => 'N'), array('textCode' => 'SORT', 'type' => 'text', 'maxLength' => 11, 'value' => 100, 'skip' => 'N')), "ownerCurrencyId" => $currencyID);
unset($bVatMode);
$this->IncludeComponentTemplate();
示例#24
0
 }
 if ($iRoleIDChif <= 0) {
     $iRoleIDChif = $CCrmRole->Add($arRoles['chif']);
 }
 if ($iRoleIDMan <= 0) {
     $iRoleIDMan = $CCrmRole->Add($arRoles['man']);
 }
 if (WIZARD_MARKETING_AND_SALES_GROUP > 0) {
     $arRel['G' . WIZARD_MARKETING_AND_SALES_GROUP] = array($iRoleID);
 }
 $CCrmRole->SetRelation($arRel);
 /* INSTALL DEMO-DATA */
 // copy files
 CopyDirFiles(WIZARD_ABSOLUTE_PATH . "/site/services/crm/images/", WIZARD_SITE_PATH . '/upload/crm', true, true);
 // Create default product catalog
 $catalogID = CCrmCatalog::EnsureDefaultExists();
 $currencyID = CCrmCurrency::GetBaseCurrencyID();
 // Creation of demo products
 require_once "product.demo.php";
 if (COption::GetOptionString('crm', '~CRM_INVOICE_INSTALL_12_5_7', 'N') !== 'Y') {
     require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/crm/install/sale_link.php";
 }
 CCrmProductDemo::Create($catalogID);
 // Add lead
 require_once "lead.demo.php";
 $CCrmLead = new CCrmLead();
 foreach ($arLeads as $ID => $arParams) {
     $arProductRows = null;
     if (isset($arParams['PRODUCT_ROWS'])) {
         $arProductRows = $arParams['PRODUCT_ROWS'];
         unset($arParams['PRODUCT_ROWS']);
示例#25
0
 protected function innerDelete($id, &$errors)
 {
     /** @global CMain $APPLICATION */
     global $APPLICATION;
     if (!CModule::IncludeModule('iblock')) {
         throw new RestException('Could not load iblock module.');
     }
     /** @var CCrmPerms $userPerms */
     $userPerms = CCrmPerms::GetCurrentUserPermissions();
     if (!$userPerms->HavePerm('CONFIG', BX_CRM_PERM_CONFIG, 'WRITE')) {
         $errors[] = 'Access denied.';
         return false;
     }
     $iblockId = intval(CCrmCatalog::EnsureDefaultExists());
     $userTypes = CCrmProductPropsHelper::GetPropsTypesByOperations(false, 'rest');
     $res = CIBlockProperty::GetByID($id, $iblockId);
     $result = false;
     if (is_object($res)) {
         $result = $res->Fetch();
     }
     unset($res);
     if (!is_array($result) || isset($result['USER_TYPE']) && !empty($result['USER_TYPE']) && !array_key_exists($result['USER_TYPE'], $userTypes)) {
         $errors[] = 'Not found';
         return false;
     }
     if (!CIBlockProperty::Delete($id)) {
         if ($e = $APPLICATION->GetException()) {
             $errors[] = $e->GetString();
         } else {
             $errors[] = 'Error on deleting product property.';
         }
         return false;
     }
     return true;
 }