public static function getMap() { global $DB, $DBType; if (function_exists('___dbCastIntToChar') !== true) { eval('function ___dbCastIntToChar($dbtype, $param)' . '{' . ' $result = $param;' . ' if (ToLower($dbtype) === "mssql")' . ' {' . ' $result = "CAST(".$param." AS VARCHAR)";' . ' }' . ' return $result;' . '}'); } return array('ID' => array('data_type' => 'integer', 'primary' => true, 'autocomplete' => true), 'DATE_INSERT' => array('data_type' => 'datetime'), 'DATE_INS' => array('data_type' => 'datetime', 'expression' => array($DB->datetimeToDateFunction('%s'), 'DATE_INSERT')), 'DATE_UPDATE' => array('data_type' => 'datetime'), 'DATE_UPD' => array('data_type' => 'datetime', 'expression' => array($DB->datetimeToDateFunction('%s'), 'DATE_UPDATE')), 'PRODUCT_ID' => array('data_type' => 'integer'), 'NAME' => array('data_type' => 'string'), 'NAME_WITH_IDENT' => array('data_type' => 'string', 'expression' => array($DB->concat('%s', '\' [\'', ___dbCastIntToChar($DBType, '%s'), '\']\''), 'NAME', 'PRODUCT_ID')), 'IBLOCK_ELEMENT' => array('data_type' => 'IBlockElementProxy', 'reference' => array('=this.PRODUCT_ID' => 'ref.ID')), 'ORDER_ID' => array('data_type' => 'integer'), 'INVOICE' => array('data_type' => 'Invoice', 'reference' => array('=this.ORDER_ID' => 'ref.ID')), 'PRICE' => array('data_type' => 'float'), 'VAT_RATE' => array('data_type' => 'float'), 'VAT_RATE_PRC' => array('data_type' => 'float', 'expression' => array('100 * %s', 'VAT_RATE')), 'QUANTITY' => array('data_type' => 'float'), 'NOTES' => array('data_type' => 'string'), 'LID' => array('data_type' => 'string'), 'SUMMARY_PRICE' => array('data_type' => 'float', 'expression' => array('(%s * %s)', 'QUANTITY', 'PRICE'))); }
public static function getMap() { global $DB, $DBType; if (function_exists('___dbCastIntToChar') !== true) { eval('function ___dbCastIntToChar($dbtype, $param)' . '{' . ' $result = $param;' . ' if (ToLower($dbtype) === "mssql")' . ' {' . ' $result = "CAST(".$param." AS VARCHAR)";' . ' }' . ' return $result;' . '}'); } return array('ID' => array('data_type' => 'integer', 'primary' => true, 'autocomplete' => true), 'FUSER_ID' => array('data_type' => 'integer'), 'FUSER' => array('data_type' => 'Fuser', 'reference' => array('=this.FUSER_ID' => 'ref.ID')), 'DATE_INSERT' => array('data_type' => 'datetime'), 'DATE_INS' => array('data_type' => 'datetime', 'expression' => array($DB->datetimeToDateFunction('%s'), 'DATE_INSERT')), 'DATE_UPDATE' => array('data_type' => 'datetime'), 'DATE_UPD' => array('data_type' => 'datetime', 'expression' => array($DB->datetimeToDateFunction('%s'), 'DATE_UPDATE')), 'PRODUCT_ID' => array('data_type' => 'integer'), 'PRODUCT' => array('data_type' => 'Product', 'reference' => array('=this.PRODUCT_ID' => 'ref.ID')), 'NAME' => array('data_type' => 'string'), 'NAME_WITH_IDENT' => array('data_type' => 'string', 'expression' => array($DB->concat('%s', '\' [\'', ___dbCastIntToChar($DBType, '%s'), '\']\''), 'NAME', 'PRODUCT_ID')), 'ORDER_ID' => array('data_type' => 'integer'), 'ORDER' => array('data_type' => 'Order', 'reference' => array('=this.ORDER_ID' => 'ref.ID')), 'PRICE' => array('data_type' => 'float'), 'DISCOUNT_PRICE' => array('data_type' => 'float'), 'DISCOUNT_NAME' => array('data_type' => 'string'), 'DISCOUNT_VALUE' => array('data_type' => 'string'), 'VAT_RATE' => array('data_type' => 'float'), 'VAT_RATE_PRC' => array('data_type' => 'float', 'expression' => array('100 * %s', 'VAT_RATE')), 'QUANTITY' => array('data_type' => 'float'), 'NOTES' => array('data_type' => 'string'), 'LID' => array('data_type' => 'string'), 'DELAY' => array('data_type' => 'boolean', 'values' => array('N', 'Y')), 'SUMMARY_PRICE' => array('data_type' => 'float', 'expression' => array('(%s * %s)', 'QUANTITY', 'PRICE')), 'SUBSCRIBE' => array('data_type' => 'boolean', 'values' => array('N', 'Y')), 'N_SUBSCRIBE' => array('data_type' => 'integer', 'expression' => array('CASE WHEN %s = \'Y\' THEN 1 ELSE 0 END', 'SUBSCRIBE')), 'SUMMARY_PURCHASING_PRICE' => array('data_type' => 'float', 'expression' => array('(%s) * %s', 'PRODUCT.PURCHASING_PRICE_IN_SITE_CURRENCY', 'QUANTITY')), 'GROSS_PROFIT' => array('data_type' => 'float', 'expression' => array('(%s) - (%s)', 'SUMMARY_PRICE', 'SUMMARY_PURCHASING_PRICE')), 'PROFITABILITY' => array('data_type' => 'float', 'expression' => array('CASE WHEN %s is NULL OR %s=0 THEN NULL ELSE (%s) * 100 / (%s) END', 'SUMMARY_PURCHASING_PRICE', 'SUMMARY_PURCHASING_PRICE', 'GROSS_PROFIT', 'SUMMARY_PURCHASING_PRICE'))); }
public static function beforeViewDataQuery(&$select, &$filter, &$group, &$order, &$limit, &$options, &$runtime) { global $DB, $DBType; if (function_exists('___dbCastIntToChar') !== true) { eval('function ___dbCastIntToChar($dbtype, $param)' . '{' . ' $result = $param;' . ' if (ToLower($dbtype) === "mssql")' . ' {' . ' $result = "CAST(".$param." AS VARCHAR)";' . ' }' . ' return $result;' . '}'); } // Runtime fields if (self::$bUsePriceTypesColumns) { foreach (self::$priceTypes as $id => $info) { if ($info['selected'] === true) { $fieldName = 'PRICE_TYPE_' . $id; $runtime[$fieldName] = array('data_type' => 'string', 'expression' => array(' (SELECT ' . $DB->Concat(___dbCastIntToChar($DBType, 'b_catalog_price.PRICE'), '\' \'', 'b_catalog_price.CURRENCY') . ' FROM b_catalog_price LEFT JOIN b_catalog_group ON b_catalog_group.ID = b_catalog_price.CATALOG_GROUP_ID WHERE b_catalog_price.PRODUCT_ID = %s AND b_catalog_group.ID = ' . $id . ' AND ( b_catalog_price.quantity_from <= 1 OR b_catalog_price.quantity_from IS NULL ) AND ( b_catalog_price.quantity_to >= 1 OR b_catalog_price.quantity_to IS NULL ))', 'ID'), 'view_column' => array('humanTitle' => $info['name'])); $select[$fieldName] = $fieldName; } } } if (self::$currentIblockFilter['value']) { $filter[] = array('LOGIC' => 'AND', (self::$currentIblockFilter['compare'] === 'EQUAL' ? '=' : '!=') . 'IBLOCK.IBLOCK_ID' => self::$currentIblockFilter['value']); } self::$currentIblockFilter['value'] = null; self::$currentIblockFilter['compare'] = null; }
public static function getMap() { // Get weight factor $siteId = ''; $weight_koef = 0; $site_currency = ''; if (class_exists('\\CBaseSaleReportHelper')) { if (\CBaseSaleReportHelper::isInitialized()) { $siteId = \CBaseSaleReportHelper::getDefaultSiteId(); if ($siteId !== null) { $weight_koef = intval(\CBaseSaleReportHelper::getDefaultSiteWeightDivider()); } // Get site currency $site_currency = \CBaseSaleReportHelper::getSiteCurrencyId(); } } if ($weight_koef <= 0) { $weight_koef = 1; } global $DB, $DBType; if (function_exists('___dbCastIntToChar') !== true) { eval('function ___dbCastIntToChar($dbtype, $param)' . '{' . ' $result = $param;' . ' if (ToLower($dbtype) === "mssql")' . ' {' . ' $result = "CAST(".$param." AS VARCHAR)";' . ' }' . ' return $result;' . '}'); } $fieldsMap = array('ID' => array('data_type' => 'integer', 'primary' => true), 'TIMESTAMP_X' => array('data_type' => 'integer'), 'DATE_UPDATED' => array('data_type' => 'datetime', 'expression' => array($DB->datetimeToDateFunction('%s'), 'TIMESTAMP_X')), 'QUANTITY' => array('data_type' => 'float'), 'PURCHASING_PRICE' => array('data_type' => 'float'), 'PURCHASING_CURRENCY' => array('data_type' => 'string'), 'IBLOCK' => array('data_type' => 'Bitrix\\Iblock\\Element', 'reference' => array('=this.ID' => 'ref.ID')), 'NAME' => array('data_type' => 'string', 'expression' => array('%s', 'IBLOCK.NAME')), 'NAME_WITH_IDENT' => array('data_type' => 'string', 'expression' => array($DB->concat('%s', '\' [\'', ___dbCastIntToChar($DBType, '%s'), '\']\''), 'NAME', 'ID')), 'ACTIVE' => array('data_type' => 'boolean', 'expression' => array('%s', 'IBLOCK.ACTIVE'), 'values' => array('N', 'Y')), 'WEIGHT' => array('data_type' => 'float'), 'WEIGHT_IN_SITE_UNITS' => array('data_type' => 'float', 'expression' => array('%s / ' . $DB->forSql($weight_koef), 'WEIGHT')), 'PRICE' => array('data_type' => 'float', 'expression' => array('(SELECT b_catalog_price.PRICE FROM b_catalog_price LEFT JOIN b_catalog_group ON b_catalog_group.ID = b_catalog_price.CATALOG_GROUP_ID WHERE b_catalog_price.PRODUCT_ID = %s AND b_catalog_group.base = \'Y\' AND ( b_catalog_price.quantity_from <= 1 OR b_catalog_price.quantity_from IS NULL ) AND ( b_catalog_price.quantity_to >= 1 OR b_catalog_price.quantity_to IS NULL))', 'ID')), 'CURRENCY' => array('data_type' => 'string', 'expression' => array('(SELECT b_catalog_price.CURRENCY FROM b_catalog_price LEFT JOIN b_catalog_group ON b_catalog_group.ID = b_catalog_price.CATALOG_GROUP_ID WHERE b_catalog_price.PRODUCT_ID = %s AND b_catalog_group.base = \'Y\' AND ( b_catalog_price.quantity_from <= 1 OR b_catalog_price.quantity_from IS NULL ) AND ( b_catalog_price.quantity_to >= 1 OR b_catalog_price.quantity_to IS NULL))', 'ID')), 'SUMMARY_PRICE' => array('data_type' => 'float', 'expression' => array('%s * %s', 'QUANTITY', 'PRICE')), 'CURRENT_CURRENCY_RATE' => array('data_type' => 'float', 'expression' => array($DBType === 'oracle' ? '(SELECT r FROM (SELECT b_catalog_currency.CURRENCY c, b_catalog_product.ID i, (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END) r FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') ORDER BY DATE_RATE DESC) WHERE i = %s AND c = %s AND ROWNUM = 1)' : '(' . $DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END) FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = %s ORDER BY DATE_RATE DESC', 1) . ')', 'ID', 'CURRENCY')), 'CURRENT_CURRENCY_RATE_CNT' => array('data_type' => 'float', 'expression' => array($DBType === 'oracle' ? '(SELECT r FROM (SELECT b_catalog_currency.CURRENCY c, b_catalog_product.ID i, (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END) r FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') ORDER BY DATE_RATE DESC) WHERE i = %s AND c = %s AND ROWNUM = 1)' : '(' . $DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END) FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = %s ORDER BY DATE_RATE DESC', 1) . ')', 'ID', 'CURRENCY')), 'CURRENT_SITE_CURRENCY_RATE' => array('data_type' => 'float', 'expression' => array($DBType === 'oracle' ? '(SELECT r FROM (SELECT b_catalog_product.ID i, (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END) r FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_currency.CURRENCY = \'' . $DB->forSql($site_currency) . '\' ORDER BY DATE_RATE DESC) WHERE i = %s AND ROWNUM = 1)' : '(' . $DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END) FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = \'' . $DB->forSql($site_currency) . '\' ORDER BY DATE_RATE DESC', 1) . ')', 'ID')), 'CURRENT_SITE_CURRENCY_RATE_CNT' => array('data_type' => 'float', 'expression' => array($DBType === 'oracle' ? '(SELECT r FROM (SELECT b_catalog_product.ID i, (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END) r FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_currency.CURRENCY = \'' . $DB->forSql($site_currency) . '\' ORDER BY DATE_RATE DESC) WHERE i = %s AND ROWNUM = 1)' : '(' . $DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END) FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = \'' . $DB->forSql($site_currency) . '\' ORDER BY DATE_RATE DESC', 1) . ')', 'ID')), 'PURCHASING_CURRENCY_RATE' => array('data_type' => 'float', 'expression' => array($DBType === 'oracle' ? '(SELECT r FROM (SELECT b_catalog_currency.CURRENCY c, b_catalog_product.ID i, (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END) r FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') ORDER BY DATE_RATE DESC) WHERE i = %s AND c = %s AND ROWNUM = 1)' : '(' . $DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END) FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = %s ORDER BY DATE_RATE DESC', 1) . ')', 'ID', 'PURCHASING_CURRENCY')), 'PURCHASING_CURRENCY_RATE_CNT' => array('data_type' => 'float', 'expression' => array($DBType === 'oracle' ? '(SELECT r FROM (SELECT b_catalog_currency.CURRENCY c, b_catalog_product.ID i, (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END) r FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') ORDER BY DATE_RATE DESC) WHERE i = %s AND c = %s AND ROWNUM = 1)' : '(' . $DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END) FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = %s ORDER BY DATE_RATE DESC', 1) . ')', 'ID', 'PURCHASING_CURRENCY')), 'PRICE_IN_SITE_CURRENCY' => array('data_type' => 'float', 'expression' => array('%s * (%s * %s / %s / %s)', 'PRICE', 'CURRENT_CURRENCY_RATE', 'CURRENT_SITE_CURRENCY_RATE_CNT', 'CURRENT_SITE_CURRENCY_RATE', 'CURRENT_CURRENCY_RATE_CNT')), 'PURCHASING_PRICE_IN_SITE_CURRENCY' => array('data_type' => 'float', 'expression' => array('%s * (%s * %s / %s / %s)', 'PURCHASING_PRICE', 'PURCHASING_CURRENCY_RATE', 'CURRENT_SITE_CURRENCY_RATE_CNT', 'CURRENT_SITE_CURRENCY_RATE', 'PURCHASING_CURRENCY_RATE_CNT')), 'SUMMARY_PRICE_IN_SITE_CURRENCY' => array('data_type' => 'float', 'expression' => array('%s * (%s * %s / %s / %s)', 'SUMMARY_PRICE', 'CURRENT_CURRENCY_RATE', 'CURRENT_SITE_CURRENCY_RATE_CNT', 'CURRENT_SITE_CURRENCY_RATE', 'CURRENT_CURRENCY_RATE_CNT')), 'VIEWS_IN_PERIOD_BY_SHOP' => array('data_type' => 'integer', 'expression' => array('(SELECT SUM(1) FROM b_catalog_product, b_sale_viewed_product WHERE %s = b_sale_viewed_product.PRODUCT_ID AND b_catalog_product.ID = b_sale_viewed_product.PRODUCT_ID AND b_sale_viewed_product.DATE_VISIT %%RT_TIME_INTERVAL%% AND b_sale_viewed_product.LID %%RT_SITE_FILTER%%)', 'ID')), 'ORDERS_IN_PERIOD_BY_SHOP' => array('data_type' => 'integer', 'expression' => array('(SELECT COUNT(DISTINCT b_sale_order.ID) FROM b_catalog_product INNER JOIN b_sale_basket ON b_catalog_product.ID = b_sale_basket.PRODUCT_ID INNER JOIN b_sale_order ON b_sale_basket.ORDER_ID = b_sale_order.ID WHERE b_catalog_product.ID = %s AND b_sale_order.PAYED = \'Y\' AND b_sale_order.DATE_INSERT %%RT_TIME_INTERVAL%% AND b_sale_basket.LID %%RT_SITE_FILTER%%)', 'ID')), 'SALED_PRODUCTS_IN_PERIOD_BY_SHOP' => array('data_type' => 'integer', 'expression' => array($DB->isNull('(SELECT SUM(b_sale_basket.QUANTITY) FROM b_sale_basket INNER JOIN b_sale_order ON b_sale_basket.ORDER_ID = b_sale_order.ID WHERE b_sale_basket.PRODUCT_ID = %s AND b_sale_order.PAYED = \'Y\' AND b_sale_order.DEDUCTED = \'Y\' AND b_sale_order.DATE_INSERT %%RT_TIME_INTERVAL%% AND b_sale_basket.LID %%RT_SITE_FILTER%%)', 0) . '+' . $DB->isNull('(SELECT SUM(b_catalog_docs_element.AMOUNT) FROM b_catalog_store_docs INNER JOIN b_catalog_docs_element on b_catalog_store_docs.ID = b_catalog_docs_element.DOC_ID WHERE b_catalog_store_docs.DOC_TYPE = \'D\' AND b_catalog_store_docs.STATUS = \'Y\' AND b_catalog_store_docs.DATE_DOCUMENT %%RT_TIME_INTERVAL%% AND b_catalog_docs_element.ELEMENT_ID = %s)', 0), 'ID', 'ID')), 'ARRIVED_PRODUCTS_IN_PERIOD_BY_SHOP' => array('data_type' => 'float', 'expression' => array('(SELECT SUM(b_catalog_docs_element.AMOUNT) FROM b_catalog_store_docs INNER JOIN b_catalog_docs_element on b_catalog_store_docs.ID = b_catalog_docs_element.DOC_ID WHERE b_catalog_store_docs.DOC_TYPE in (\'A\', \'R\') AND b_catalog_store_docs.STATUS = \'Y\' AND b_catalog_store_docs.DATE_DOCUMENT %%RT_TIME_INTERVAL%% AND b_catalog_docs_element.ELEMENT_ID = %s)', 'ID')), 'CONVERSION' => array('data_type' => 'float', 'expression' => array('100 * CASE WHEN %s IS NULL OR %s = 0 THEN NULL ELSE %s / %s END', 'VIEWS_IN_PERIOD_BY_SHOP', 'VIEWS_IN_PERIOD_BY_SHOP', 'ORDERS_IN_PERIOD_BY_SHOP', 'VIEWS_IN_PERIOD_BY_SHOP'))); return $fieldsMap; }
public static function getMap() { // Get weight factor $siteId = ''; $weight_koef = 0; $site_currency = ''; if (class_exists('\\CBaseSaleReportHelper')) { if (\CBaseSaleReportHelper::isInitialized()) { $siteId = \CBaseSaleReportHelper::getDefaultSiteId(); if ($siteId !== null) { $weight_koef = intval(\CBaseSaleReportHelper::getDefaultSiteWeightDivider()); } // Get site currency $site_currency = \CBaseSaleReportHelper::getSiteCurrencyId(); } } if ($weight_koef <= 0) { $weight_koef = 1; } global $DB, $DBType; if (function_exists('___dbCastIntToChar') !== true) { eval('function ___dbCastIntToChar($dbtype, $param)' . '{' . ' $result = $param;' . ' if (ToLower($dbtype) === "mssql")' . ' {' . ' $result = "CAST(".$param." AS VARCHAR)";' . ' }' . ' return $result;' . '}'); } $fieldsMap = array('ID' => array('data_type' => 'integer', 'primary' => true), 'TIMESTAMP_X' => array('data_type' => 'integer'), 'DATE_UPDATED' => array('data_type' => 'datetime', 'expression' => array($DB->datetimeToDateFunction('%s'), 'TIMESTAMP_X')), 'QUANTITY' => array('data_type' => 'float'), 'PURCHASING_PRICE' => array('data_type' => 'float'), 'PURCHASING_CURRENCY' => array('data_type' => 'string'), 'IBLOCK' => array('data_type' => 'Bitrix\\Iblock\\Element', 'reference' => array('=this.ID' => 'ref.ID')), 'NAME' => array('data_type' => 'string', 'expression' => array('%s', 'IBLOCK.NAME')), 'NAME_WITH_IDENT' => array('data_type' => 'string', 'expression' => array($DB->concat('%s', '\' [\'', ___dbCastIntToChar($DBType, '%s'), '\']\''), 'NAME', 'ID')), 'ACTIVE' => array('data_type' => 'boolean', 'expression' => array('%s', 'IBLOCK.ACTIVE'), 'values' => array('N', 'Y')), 'WEIGHT' => array('data_type' => 'float'), 'WEIGHT_IN_SITE_UNITS' => array('data_type' => 'float', 'expression' => array('%s / ' . $DB->forSql($weight_koef), 'WEIGHT')), 'PRICE' => array('data_type' => 'float', 'expression' => array('(SELECT b_catalog_price.PRICE FROM b_catalog_price LEFT JOIN b_catalog_group ON b_catalog_group.ID = b_catalog_price.CATALOG_GROUP_ID WHERE b_catalog_price.PRODUCT_ID = %s AND b_catalog_group.base = \'Y\' AND ( b_catalog_price.quantity_from <= 1 OR b_catalog_price.quantity_from IS NULL ) AND ( b_catalog_price.quantity_to >= 1 OR b_catalog_price.quantity_to IS NULL))', 'ID')), 'CURRENCY' => array('data_type' => 'string', 'expression' => array('(SELECT b_catalog_price.CURRENCY FROM b_catalog_price LEFT JOIN b_catalog_group ON b_catalog_group.ID = b_catalog_price.CATALOG_GROUP_ID WHERE b_catalog_price.PRODUCT_ID = %s AND b_catalog_group.base = \'Y\' AND ( b_catalog_price.quantity_from <= 1 OR b_catalog_price.quantity_from IS NULL ) AND ( b_catalog_price.quantity_to >= 1 OR b_catalog_price.quantity_to IS NULL))', 'ID')), 'SUMMARY_PRICE' => array('data_type' => 'float', 'expression' => array('%s * %s', 'QUANTITY', 'PRICE')), 'CURRENT_CURRENCY_RATE' => array('data_type' => 'float', 'expression' => array($DBType === 'oracle' ? '(SELECT r FROM (SELECT b_catalog_currency.CURRENCY c, b_catalog_product.ID i, (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END) r FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') ORDER BY DATE_RATE DESC) WHERE i = %s AND c = %s AND ROWNUM = 1)' : '(' . $DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END) FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = %s ORDER BY DATE_RATE DESC', 1) . ')', 'ID', 'CURRENCY')), 'CURRENT_CURRENCY_RATE_CNT' => array('data_type' => 'float', 'expression' => array($DBType === 'oracle' ? '(SELECT r FROM (SELECT b_catalog_currency.CURRENCY c, b_catalog_product.ID i, (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END) r FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') ORDER BY DATE_RATE DESC) WHERE i = %s AND c = %s AND ROWNUM = 1)' : '(' . $DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END) FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = %s ORDER BY DATE_RATE DESC', 1) . ')', 'ID', 'CURRENCY')), 'CURRENT_SITE_CURRENCY_RATE' => array('data_type' => 'float', 'expression' => array($DBType === 'oracle' ? '(SELECT r FROM (SELECT b_catalog_product.ID i, (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END) r FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_currency.CURRENCY = \'' . $DB->forSql($site_currency) . '\' ORDER BY DATE_RATE DESC) WHERE i = %s AND ROWNUM = 1)' : '(' . $DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END) FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = \'' . $DB->forSql($site_currency) . '\' ORDER BY DATE_RATE DESC', 1) . ')', 'ID')), 'CURRENT_SITE_CURRENCY_RATE_CNT' => array('data_type' => 'float', 'expression' => array($DBType === 'oracle' ? '(SELECT r FROM (SELECT b_catalog_product.ID i, (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END) r FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_currency.CURRENCY = \'' . $DB->forSql($site_currency) . '\' ORDER BY DATE_RATE DESC) WHERE i = %s AND ROWNUM = 1)' : '(' . $DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END) FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = \'' . $DB->forSql($site_currency) . '\' ORDER BY DATE_RATE DESC', 1) . ')', 'ID')), 'PURCHASING_CURRENCY_RATE' => array('data_type' => 'float', 'expression' => array($DBType === 'oracle' ? '(SELECT r FROM (SELECT b_catalog_currency.CURRENCY c, b_catalog_product.ID i, (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END) r FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') ORDER BY DATE_RATE DESC) WHERE i = %s AND c = %s AND ROWNUM = 1)' : '(' . $DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE IS NOT NULL THEN b_catalog_currency_rate.RATE ELSE b_catalog_currency.AMOUNT END) FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = %s ORDER BY DATE_RATE DESC', 1) . ')', 'ID', 'PURCHASING_CURRENCY')), 'PURCHASING_CURRENCY_RATE_CNT' => array('data_type' => 'float', 'expression' => array($DBType === 'oracle' ? '(SELECT r FROM (SELECT b_catalog_currency.CURRENCY c, b_catalog_product.ID i, (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END) r FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') ORDER BY DATE_RATE DESC) WHERE i = %s AND c = %s AND ROWNUM = 1)' : '(' . $DB->topSql('SELECT (CASE WHEN b_catalog_currency_rate.RATE_CNT IS NOT NULL THEN b_catalog_currency_rate.RATE_CNT ELSE b_catalog_currency.AMOUNT_CNT END) FROM b_catalog_product INNER JOIN b_catalog_currency ON 1=1 LEFT JOIN b_catalog_currency_rate ON (b_catalog_currency.CURRENCY = b_catalog_currency_rate.CURRENCY AND b_catalog_currency_rate.DATE_RATE <= ' . $DB->datetimeToDateFunction('b_catalog_product.TIMESTAMP_X') . ') WHERE b_catalog_product.ID = %s AND b_catalog_currency.CURRENCY = %s ORDER BY DATE_RATE DESC', 1) . ')', 'ID', 'PURCHASING_CURRENCY')), 'PRICE_IN_SITE_CURRENCY' => array('data_type' => 'float', 'expression' => array('%s * (%s * %s / %s / %s)', 'PRICE', 'CURRENT_CURRENCY_RATE', 'CURRENT_SITE_CURRENCY_RATE_CNT', 'CURRENT_SITE_CURRENCY_RATE', 'CURRENT_CURRENCY_RATE_CNT')), 'PURCHASING_PRICE_IN_SITE_CURRENCY' => array('data_type' => 'float', 'expression' => array('%s * (%s * %s / %s / %s)', 'PURCHASING_PRICE', 'PURCHASING_CURRENCY_RATE', 'CURRENT_SITE_CURRENCY_RATE_CNT', 'CURRENT_SITE_CURRENCY_RATE', 'PURCHASING_CURRENCY_RATE_CNT')), 'SUMMARY_PRICE_IN_SITE_CURRENCY' => array('data_type' => 'float', 'expression' => array('%s * (%s * %s / %s / %s)', 'SUMMARY_PRICE', 'CURRENT_CURRENCY_RATE', 'CURRENT_SITE_CURRENCY_RATE_CNT', 'CURRENT_SITE_CURRENCY_RATE', 'CURRENT_CURRENCY_RATE_CNT'))); return $fieldsMap; }