private static function EnsureProduct($externalID, $catalogID, $arFields) { $rsProducts = CCrmProduct::GetList(array(), array('CATALOG_ID' => $catalogID, 'ORIGIN_ID' => $externalID), array('ID')); $arProduct = $rsProducts ? $rsProducts->Fetch() : false; if (is_array($arProduct)) { return intval($arProduct['ID']); } $arFields['CATALOG_ID'] = $catalogID; $arFields['ORIGIN_ID'] = $externalID; return CCrmProduct::Add($arFields); }
public static function PrepareListItems($catalogID = 0) { $catalogID = intval($catalogID); $result = array(); $filter = array('ACTIVE' => 'Y'); if ($catalogID > 0) { $filter['CATALOG_ID'] = $catalogID; } $rs = CCrmProduct::GetList(array('SORT' => 'ASC', 'NAME' => 'ASC'), $filter, array('ID', 'NAME')); while ($ar = $rs->Fetch()) { $result[$ar['ID']] = $ar['NAME']; } return $result; }
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } $arInvoices = array(); $dbProduct = CCrmProduct::GetList(array(), array(), array('*'), array('nTopCount' => 1)); if ($arProduct = $dbProduct->Fetch()) { CModule::IncludeModule("sale"); $personTypes = CCrmPaySystem::getPersonTypeIDs(); $arFields = array("ORDER_TOPIC" => GetMessage("CRM_DEMO_INVOCIE_1_SUBJ"), "STATUS_ID" => "P", "DATE_INSERT" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL'), "DATE_BILL" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'SHORT'), "PAY_VOUCHER_DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL'), "DATE_PAY_BEFORE" => ConvertTimeStamp(time() + 8000009 + CTimeZone::GetOffset(), 'SHORT'), "RESPONSIBLE_ID" => 1, "UF_CONTACT_ID" => $arContacts["45"]['ID'], "PAY_VOUCHER_NUM" => 456, "DATE_MARKED" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL'), "PRODUCT_ROWS" => array(array("ID" => 0, "PRODUCT_ID" => $arProduct["ID"], "PRODUCT_NAME" => $arProduct["NAME"], "QUANTITY" => 1, "PRICE" => $arProduct["PRICE"])), "PERSON_TYPE_ID" => $personTypes["CONTACT"], "INVOICE_PROPERTIES" => array()); $paySystems = CCrmPaySystem::GetPaySystems($personTypes["CONTACT"]); foreach ($paySystems as $id => $paySystem) { $arFields["PAY_SYSTEM_ID"] = $id; } $arAllProps = CCrmInvoice::GetPropertiesInfo($personTypes["CONTACT"]); foreach ($arAllProps as $arProps) { foreach ($arProps as $key => $prop) { if ($key == "FIO") { $arFields["INVOICE_PROPERTIES"][$prop["ID"]] = $arContacts["45"]["LAST_NAME"]; } } } $arInvoices[] = $arFields; $arFields = array("ORDER_TOPIC" => GetMessage("CRM_DEMO_INVOCIE_2_SUBJ"), "STATUS_ID" => "N", "DATE_INSERT" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL'), "DATE_BILL" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'SHORT'), "PAY_VOUCHER_DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL'), "DATE_PAY_BEFORE" => ConvertTimeStamp(time() + 8000009 + CTimeZone::GetOffset(), 'SHORT'), "RESPONSIBLE_ID" => 1, "UF_COMPANY_ID" => $arCompany["38"]['ID'], "PRODUCT_ROWS" => array(array("ID" => 0, "PRODUCT_ID" => $arProduct["ID"], "PRODUCT_NAME" => $arProduct["NAME"], "QUANTITY" => 1, "PRICE" => $arProduct["PRICE"])), "PERSON_TYPE_ID" => $personTypes["COMPANY"], "INVOICE_PROPERTIES" => array()); $paySystems = CCrmPaySystem::GetPaySystems($personTypes["COMPANY"]); foreach ($paySystems as $id => $paySystem) { $arFields["PAY_SYSTEM_ID"] = $id; } $arAllProps = CCrmInvoice::GetPropertiesInfo($personTypes["COMPANY"]); foreach ($arAllProps as $arProps) {
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(); }
$productID = CCrmProduct::Add($productFields); if (!$productID) { $err = CCrmProduct::GetLastError(); if (!isset($err[0])) { $err = GetMessage('CRM_PRODUCT_ADD_UNKNOWN_ERROR'); } } } if ($bAjax || $bAjaxSubmit) { $APPLICATION->RestartBuffer(); $ajaxResponse = array('err' => '', 'productId' => 0, 'productData' => array()); if (isset($err[0])) { $ajaxResponse['err'] = $err; } else { $ajaxResponse['productId'] = $productID; $dbRes = CCrmProduct::GetList(array(), array('ID' => $productID, '~REAL_PRICE' => true), array('ID', 'NAME', 'ACTIVE', 'PRICE', 'CURRENCY_ID', 'MEASURE', 'VAT_ID', 'VAT_INCLUDED'), array('nTopCount' => 1)); if ($row = $dbRes->Fetch()) { if ($row['ACTIVE'] === 'Y') { $currencyTo = isset($_POST['currencyTo']) ? $_POST['currencyTo'] : ''; $currencyFrom = isset($row['CURRENCY_ID']) ? $row['CURRENCY_ID'] : ''; if (strlen($currencyFrom) > 0 && strlen($currencyTo) > 0 && $currencyFrom !== $currencyTo) { $row['PRICE'] = CCrmCurrency::ConvertMoney(doubleval($row['PRICE']), $currencyFrom, $currencyTo); } $ajaxResponse['productData'] = $row; $measureInfo = array(); if (isset($row['MEASURE']) && intval($row['MEASURE']) > 0) { $measureInfo = \Bitrix\Crm\Measure::getProductMeasures(intval($row['ID'])); $measureInfo = $measureInfo[intval($row['ID'])][0]; } else { $measureInfo = \Bitrix\Crm\Measure::getDefaultMeasure(); }
$navParams['bShowAll'] = !$enablePaging; if ($enableSearch) { $filter += $CGridOptions->GetFilter(array(array('id' => 'NAME'))); if (!empty($filter)) { if (isset($filter['NAME'])) { $filter['%NAME'] = $filter['NAME']; unset($filter['NAME']); } } else { $enableSearch = $arResult['ENABLE_SEARCH'] = false; } } $arResult['PRODUCTS'] = array(); $arPricesSelect = $arVatsSelect = array(); $select = CCrmProduct::DistributeProductSelect($select, $arPricesSelect, $arVatsSelect); $dbProducts = CCrmProduct::GetList($sort, $filter, $select, $navParams); $dbProducts->NavStart($navParams['nPageSize'], false); $arResult['PAGE_NAVNUM'] = intval($dbProducts->NavNum); // pager index $arResult['PAGE_NUMBER'] = intval($dbProducts->NavPageNomer); // current page index $arResult['PAGE_NAVCOUNT'] = intval($dbProducts->NavPageCount); // page count $arResult['PAGER_PARAM'] = "PAGEN_{$arResult['PAGE_NAVNUM']}"; $arResult['PAGE_NEXT_NUMBER'] = $arResult['PAGE_NUMBER'] + 1; $productParams = array('CURRENCY_ID' => $currencyID, 'SECTIONS' => &$arResult['ALL_SECTIONS']); $arProducts = $arProductId = array(); while ($product = $dbProducts->GetNext()) { foreach ($arPricesSelect as $fieldName) { $product['~' . $fieldName] = $product[$fieldName] = null; }
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); }
public static function Delete($ID) { if (!CModule::IncludeModule('catalog')) { return false; } self::$LAST_ERROR = ''; global $DB; $tableName = CCrmCatalog::TABLE_NAME; $ID = intval($ID); if (!is_array(self::GetByID($ID))) { // Is no exists return true; } $events = GetModuleEvents('crm', 'OnBeforeCrmCatalogDelete'); while ($arEvent = $events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array($ID)) === false) { return false; } } $dbRes = CCrmProduct::GetList(array(), array('CATALOG_ID' => $ID), array('ID')); while ($arRes = $dbRes->Fetch()) { $productID = $arRes['ID']; if (!CCrmProduct::Delete($productID)) { self::RegisterError(sprintf('Deletion of CrmCatalog(ID=%d) is canceled. Could not delete CrmProduct(ID = %d).', $ID, $productID)); return false; } } if (!$DB->Query('DELETE FROM ' . $tableName . ' WHERE ID = ' . $ID, true)) { return false; } // -------------- remove from catalog module --------------> $CCatalog = new CCatalog(); if (!$CCatalog->Delete($ID)) { return false; } // <-------------- remove from catalog module -------------- CCrmEntityHelper::RemoveCached(self::CACHE_NAME, $ID); $events = GetModuleEvents('crm', 'OnCrmCatalogDelete'); while ($arEvent = $events->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID)); } return true; }
// Default currency exchange rates are used //$dstExchRate = isset($_REQUEST['EXCH_RATE']) ? (double)$_REQUEST['EXCH_RATE'] : 0; //if($dstExchRate == 0) //{ // $dstExchRate = is_array($dstCurrency) ? $dstCurrency['EXCH_RATE'] : 1.0; //} $enableRawPrices = isset($_REQUEST['ENABLE_RAW_PRICES']) && strtoupper($_REQUEST['ENABLE_RAW_PRICES']) === 'Y'; $limit = isset($_REQUEST['LIMIT']) ? intval($_REQUEST['LIMIT']) : 0; /*$arNavStartParams = false; if ($limit > 0) $arNavStartParams = array('nTopCount' => $limit);*/ $arSelect = array('ID', 'NAME', 'PRICE', 'CURRENCY_ID'); $arPricesSelect = $arVatsSelect = array(); $arSelect = CCrmProduct::DistributeProductSelect($arSelect, $arPricesSelect, $arVatsSelect); $obRes = CCrmProduct::GetList(array(), $arFilter, $arSelect); $arProducts = $arProductId = array(); $pos = 0; $searchUpper = ToUpper($search); $nameUpper = ''; $arSort = array('RANK1' => array(), 'NAME' => array(), 'ID' => array()); while ($arRes = $obRes->Fetch()) { foreach ($arPricesSelect as $fieldName) { $arRes[$fieldName] = null; } foreach ($arVatsSelect as $fieldName) { $arRes[$fieldName] = null; } $nameUpper = ToUpper($arRes['NAME']); $pos = strpos($nameUpper, $searchUpper); $arRes['RANK1'] = $pos === false ? 0 : $pos + 1;
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; }
$arSelect = array('ID', 'TITLE', 'STAGE_ID'); $ar = array(); $obRes = CCrmDeal::GetList(array('ID' => 'DESC'), array('ID' => $arSelected['DEAL']), $arSelect); while ($arRes = $obRes->Fetch()) { $arRes['SID'] = $arResult['PREFIX'] == 'Y' ? 'D_' . $arRes['ID'] : $arRes['ID']; if (isset($arResult['SELECTED'][$arRes['SID']])) { unset($arResult['SELECTED'][$arRes['SID']]); $sSelected = 'Y'; } else { $sSelected = 'N'; } $ar[] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => isset($arDealStageList[$arRes['STAGE_ID']]) ? $arDealStageList[$arRes['STAGE_ID']] : '', 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_show'), array('deal_id' => $arRes['ID'])), 'type' => 'deal', 'selected' => $sSelected); } $arResult['ELEMENT'] = array_merge($ar, $arResult['ELEMENT']); } if (isset($arSettings['PRODUCT']) && $arSettings['PRODUCT'] == 'Y' && isset($arSelected['PRODUCT']) && !empty($arSelected['PRODUCT'])) { $ar = array(); $obRes = CCrmProduct::GetList(array('ID' => 'DESC'), array('ID' => $arSelected['PRODUCT']), array('ID', 'NAME', 'PRICE', 'CURRENCY_ID')); while ($arRes = $obRes->Fetch()) { $arRes['SID'] = $arResult['PREFIX'] == 'Y' ? 'D_' . $arRes['ID'] : $arRes['ID']; if (isset($arResult['SELECTED'][$arRes['SID']])) { unset($arResult['SELECTED'][$arRes['SID']]); $sSelected = 'Y'; } else { $sSelected = 'N'; } $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); } $arResult['ELEMENT'] = array_merge($ar, $arResult['ELEMENT']); } }
public static function GetProductName($arRow) { if (isset($arRow['PRODUCT_NAME']) && $arRow['PRODUCT_NAME'] !== '') { return $arRow['PRODUCT_NAME']; } $productID = isset($arRow['PRODUCT_ID']) ? (int) $arRow['PRODUCT_ID'] : 0; if ($productID > 0) { $rs = CCrmProduct::GetList(array(), array('ID' => $productID), array('NAME')); return ($ary = $rs->Fetch()) ? $ary['NAME'] : $productID; } return "[{$productID}]"; }
$uid = isset($arParams['UID']) ? $arParams['UID'] : ''; if (!isset($arParams['UID']) || $arParams['UID'] === '') { $uid = 'mobile_crm_product_row_edit'; } else { $uid = str_replace(array('#CONTEXT_ID#'), array($contextID), $uid); } $arResult['UID'] = $uid; $productID = $arParams['PRODUCT_ID'] = isset($arParams['PRODUCT_ID']) ? intval($arParams['PRODUCT_ID']) : 0; if ($productID <= 0 && isset($_REQUEST['product_id'])) { $productID = intval($_REQUEST['product_id']); } $arResult['PRODUCT_ID'] = $productID; if ($productID <= 0) { $arResult['PRODUCT_NAME'] = ''; } else { $dbProduct = CCrmProduct::GetList(array(), array('=ID' => $productID), array('NAME')); $product = $dbProduct ? $dbProduct->Fetch() : null; $arResult['PRODUCT_NAME'] = is_array($product) && isset($product['NAME']) ? $product['NAME'] : $productID; } $currencyID = $arParams['CURRENCY_ID'] = isset($arParams['CURRENCY_ID']) ? $arParams['CURRENCY_ID'] : ''; if ($currencyID === '' && isset($_REQUEST['currency_id'])) { $currencyID = $_REQUEST['currency_id']; } if ($currencyID === '') { $currencyID = CCrmCurrency::GetBaseCurrencyID(); } $arResult['CURRENCY_ID'] = $currencyID; $price = $arParams['PRICE'] = isset($arParams['PRICE']) ? doubleval($arParams['PRICE']) : 0.0; if ($price <= 0 && isset($_REQUEST['price'])) { $price = doubleval($_REQUEST['price']); }
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; }
$sSelected = 'Y'; } else { $sSelected = 'N'; } $clientTitle = !empty($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : ''; $clientTitle .= ($clientTitle !== '' && !empty($arRes['CONTACT_FULL_NAME']) ? ', ' : '') . $arRes['CONTACT_FULL_NAME']; $ar[] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => $clientTitle, 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_quote_show'), array('quote_id' => $arRes['ID'])), 'type' => 'quote', 'selected' => $sSelected); } $arResult['ELEMENT'] = array_merge($ar, $arResult['ELEMENT']); } if (isset($arSettings['PRODUCT']) && $arSettings['PRODUCT'] == 'Y' && isset($arSelected['PRODUCT']) && !empty($arSelected['PRODUCT'])) { $ar = array(); $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 (!$currency) { ShowError(GetMessage('CRM_CURRENCY_IS_NOT_FOUND', array('#CURRENCY_ID#' => $currencyID))); return; } $arResult['CURRENCY_FORMAT'] = CCrmCurrency::GetCurrencyFormatString($currencyID); //$exchRate = $arResult['EXCH_RATE'] = isset($arParams['EXCH_RATE']) ? (double)$arParams['EXCH_RATE'] : 1.0; //$arResult['CURRENCY_DISPLAY_NAME'] = $currency['ID']; //ID is ISO 4217 // Prepare source data if (isset($arParams['PRODUCT_ROWS']) && is_array($arParams['PRODUCT_ROWS'])) { $arResult['PRODUCT_ROWS'] = $arParams['PRODUCT_ROWS']; foreach ($arResult['PRODUCT_ROWS'] as &$arProdRow) { $productID = intval($arProdRow['PRODUCT_ID']); if (isset($arProdRow['PRODUCT_NAME'])) { continue; } $dbRes = CCrmProduct::GetList(array(), array('ID' => $productID), array('NAME')); $arProdRow['PRODUCT_NAME'] = is_array($arRes = $dbRes->Fetch()) ? $arRes['NAME'] : '[' . strval($productID) . ']'; } unset($arProdRow); } else { if ($arResult['INVOICE_MODE']) { $arResult['PRODUCT_ROWS'] = CCrmInvoice::GetProductRows($ownerID); } else { $arResult['PRODUCT_ROWS'] = $ownerID > 0 ? CCrmProductRow::LoadRows($ownerType, $ownerID) : array(); } } if ($bCopy) { foreach ($arResult['PRODUCT_ROWS'] as &$row) { if (isset($row['ID'])) { $row['ID'] = 0; }
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; }
$arResultData = array(); if (!$bSkipSections) { $obSection = new CIBlockSection(); $rsSection = $obSection->GetList($arResult['SORT'], $arSectionFilter, false, $arSelect); while ($arSectionRow = $rsSection->Fetch()) { $arSectionRow['TYPE'] = 'S'; $arResultData[] = $arSectionRow; } unset($obSection, $rsSection, $arSectionRow); } unset($arSectionFilter); // SECTIONS <-- // PRODUCTS --> $arPricesSelect = $arVatsSelect = array(); $arSelect = CCrmProduct::DistributeProductSelect($arSelect, $arPricesSelect, $arVatsSelect); $rsProduct = CCrmProduct::GetList($arResult['SORT'], $arFilter, $arSelect); while ($arProductRow = $rsProduct->Fetch()) { $arProductRow['TYPE'] = 'P'; $arResultData[] = $arProductRow; } unset($rsProduct, $arProductRow); //$obRes = CCrmProduct::GetList($arResult['SORT'], $arFilter, $arSelect, $arNavParams); $obRes = new CDBResult(); $obRes->InitFromArray($arResultData); $obRes->NavStart($arNavParams); $arResult['PRODUCTS'] = array(); //$arResult['PRODUCT_ID_ARY'] = array(); $arResult['PERMS']['ADD'] = true; //!$CCrmProduct->cPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'ADD'); $arResult['PERMS']['WRITE'] = true; //!$CCrmProduct->cPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'WRITE');