Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE PACKAGE BODY RS24_CATALOG_BUILDER_PKG IS
- FUNCTION TEXT_QUERY(P_FLEX_CONTEXT_CODE VARCHAR2) RETURN CLOB IS
- V_QUERY CLOB;
- V_QUERY1 CLOB;
- V_QUERY11 CLOB;
- V_QUERY_TAB VARCHAR2(4000) := '';
- V_QUERY_WHERE VARCHAR2(4000) := '';
- L_UOM_COL VARCHAR2(240);
- L_VAL_COL VARCHAR2(240);
- L_ATTR_GROUP_ID NUMBER;
- L_ATTR_GROUP_ID_STR NUMBER;
- NUM NUMBER;
- DATABASE_COLUMN_TEMP VARCHAR2(4000) := '';
- DATA_TYPE_TEMP VARCHAR2(4000) := '';
- L_UOM_COL_TEMP VARCHAR2(240);
- L_VAL_COL_TEMP VARCHAR2(240);
- L_ITEM_CATALOG_GROUP_ID VARCHAR2(240);
- BEGIN
- NUM := 0;
- L_ATTR_GROUP_ID_STR := 0;
- DBMS_LOB.CREATETEMPORARY(V_QUERY, TRUE);
- DBMS_LOB.CREATETEMPORARY(V_QUERY1, TRUE);
- DBMS_LOB.CREATETEMPORARY(V_QUERY11, TRUE);
- SELECT ICG.ITEM_CATALOG_GROUP_ID
- INTO L_ITEM_CATALOG_GROUP_ID
- FROM MTL_ITEM_CATALOG_GROUPS_VL ICG
- WHERE ICG.SEGMENT4 = DECODE(SUBSTR(P_FLEX_CONTEXT_CODE, 1, 7),
- 'XXRSV_E',
- LTRIM(P_FLEX_CONTEXT_CODE, 'XXRSV_'),
- P_FLEX_CONTEXT_CODE);
- FOR C_COL IN (SELECT A.DESCRIPTION,
- A.SEQUENCE,
- A.ATTR_GROUP_ID,
- A.DATABASE_COLUMN,
- A.ATTR_NAME,
- A.ATTR_DISPLAY_NAME,
- A.DATA_TYPE,
- A.REQUIRED_FLAG,
- AG.ATTR_GROUP_NAME
- FROM XXRSV_ATTR_GROUPS AG, XXRSV_ATTRS A
- WHERE A.ATTR_GROUP_ID = AG.ATTR_GROUP_ID
- AND A.ENABLED_FLAG = 'Y'
- AND AG.DATA_LEVEL = '1'
- AND AG.ENABLED_FLAG = 'Y'
- AND AG.ATTR_GROUP_NAME LIKE P_FLEX_CONTEXT_CODE || '%'
- AND SUBSTR(A.ATTR_DISPLAY_NAME, -3, 3) <> ' по'
- AND NOT EXISTS
- (SELECT 1
- FROM (SELECT FV.PARENT_FLEX_VALUE_LOW, -- КАТ ETIM
- FV.FLEX_VALUE_MEANING AS ATTR5 -- АТРИБУТ_5
- FROM FND_FLEX_VALUESET_V FVS
- JOIN FND_FLEX_VALUES_VL FV
- ON FV.FLEX_VALUE_SET_ID =
- FVS.FLEX_VALUE_SET_ID
- AND TRUNC(SYSDATE) BETWEEN
- NVL(FV.START_DATE_ACTIVE,
- TRUNC(SYSDATE)) AND
- NVL(FV.END_DATE_ACTIVE,
- TRUNC(SYSDATE))
- AND FV.ENABLED_FLAG = 'Y'
- WHERE FVS.FLEX_VALUE_SET_NAME =
- 'XXRSV_ETIM_5.0_7.0') ETIM5
- WHERE 1 = 1
- AND ETIM5.ATTR5 = A.ATTR_NAME
- AND ETIM5.PARENT_FLEX_VALUE_LOW =
- DECODE(SUBSTR(P_FLEX_CONTEXT_CODE, 1, 7),
- 'XXRSV_E',
- LTRIM(P_FLEX_CONTEXT_CODE, 'XXRSV_'),
- P_FLEX_CONTEXT_CODE)
- AND NOT EXISTS
- (SELECT 1
- FROM (SELECT FV.PARENT_FLEX_VALUE_LOW, -- КАТ ETIM
- FV.DESCRIPTION AS ATTR7 -- АТРИБУТ_7
- FROM FND_FLEX_VALUESET_V FVS
- JOIN FND_FLEX_VALUES_VL FV
- ON FV.FLEX_VALUE_SET_ID =
- FVS.FLEX_VALUE_SET_ID
- AND TRUNC(SYSDATE) BETWEEN
- NVL(FV.START_DATE_ACTIVE,
- TRUNC(SYSDATE)) AND
- NVL(FV.END_DATE_ACTIVE,
- TRUNC(SYSDATE))
- AND FV.ENABLED_FLAG = 'Y'
- WHERE FVS.FLEX_VALUE_SET_NAME =
- 'XXRSV_ETIM_5.0_7.0') ETIM7
- WHERE ETIM5.PARENT_FLEX_VALUE_LOW =
- ETIM7.PARENT_FLEX_VALUE_LOW
- AND ETIM5.ATTR5 = ETIM7.ATTR7))
- ORDER BY A.ATTR_GROUP_ID, A.DESCRIPTION, A.SEQUENCE) LOOP
- --------------------------------------------------------------------
- --ADDING IN SELECT TABLE AND CONDITIONS FOR EACH GROUP ATTRIBUTES---
- DBMS_LOB.APPEND(V_QUERY1, ',');
- L_ATTR_GROUP_ID := C_COL.ATTR_GROUP_ID;
- IF L_ATTR_GROUP_ID_STR != L_ATTR_GROUP_ID THEN
- L_ATTR_GROUP_ID_STR := L_ATTR_GROUP_ID;
- V_QUERY_TAB := V_QUERY_TAB || 'XXRSV_ATTR_VALUES AV' ||
- TO_CHAR(L_ATTR_GROUP_ID_STR) || ',';
- IF NUM = 0 THEN
- V_QUERY_WHERE := V_QUERY_WHERE || '
- AND AV' || TO_CHAR(L_ATTR_GROUP_ID_STR) ||
- '.ATTR_GROUP_ID(+) = ' || L_ATTR_GROUP_ID_STR || '
- AND AV' || TO_CHAR(L_ATTR_GROUP_ID_STR) ||
- '.ORGANIZATION_ID(+) = XXRSV_GLOBALS.GET_MAIN_ORG_ID
- AND P.ITEM_ID = AV' ||
- TO_CHAR(L_ATTR_GROUP_ID_STR) ||
- '.INVENTORY_ITEM_ID(+)';
- NUM := 1;
- ELSE
- V_QUERY_WHERE := V_QUERY_WHERE || '
- AND AV' || TO_CHAR(L_ATTR_GROUP_ID_STR) ||
- '.ATTR_GROUP_ID(+) = ' || L_ATTR_GROUP_ID_STR ||
- ' AND AV' || TO_CHAR(L_ATTR_GROUP_ID_STR) ||
- '.ORGANIZATION_ID(+) = XXRSV_GLOBALS.GET_MAIN_ORG_ID
- AND P.ITEM_ID = AV' ||
- TO_CHAR(L_ATTR_GROUP_ID_STR) ||
- '.INVENTORY_ITEM_ID(+)';
- END IF;
- END IF;
- --THE END OF THE ADDITION---------------------------------------------
- --COMBINING THE CHARACTERISTICS OF THE TYPE "FROM - IN"---------------
- IF (SUBSTR(C_COL.ATTR_DISPLAY_NAME, -2, 2) = ' с') THEN
- BEGIN
- SELECT A.DATABASE_COLUMN, A.DATA_TYPE
- INTO DATABASE_COLUMN_TEMP, DATA_TYPE_TEMP
- FROM XXRSV_ATTR_GROUPS AG, XXRSV_ATTRS A
- WHERE A.ATTR_GROUP_ID = AG.ATTR_GROUP_ID
- AND A.ENABLED_FLAG = 'Y'
- AND AG.DATA_LEVEL = '1'
- AND AG.ENABLED_FLAG = 'Y'
- AND AG.ATTR_GROUP_NAME LIKE P_FLEX_CONTEXT_CODE || '%'
- AND A.ATTR_NAME = C_COL.ATTR_NAME || '_1';
- EXCEPTION
- WHEN OTHERS THEN
- DATABASE_COLUMN_TEMP := '###';
- END;
- IF (DATABASE_COLUMN_TEMP = '###') THEN
- IF C_COL.DATA_TYPE = 'N' THEN
- L_VAL_COL := 'AV' || TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- C_COL.DATABASE_COLUMN;
- L_UOM_COL := REPLACE(L_VAL_COL, 'N', 'UOM');
- DBMS_LOB.APPEND(V_QUERY1,
- '
- NVL(XXRSV_ENDECA_PKG.GET_STR_FEATURE(' ||
- L_VAL_COL || ', ' || L_UOM_COL ||
- '), ''Не определено'') AS ' || 'tech_' ||
- C_COL.ATTR_NAME);
- ELSE
- DBMS_LOB.APPEND(V_QUERY1,
- '
- NVL(AV' || TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- C_COL.DATABASE_COLUMN ||
- ', ''Не определено'') AS ' || 'tech_' ||
- C_COL.ATTR_NAME);
- END IF;
- ELSE
- IF DATA_TYPE_TEMP = 'N' THEN
- L_VAL_COL_TEMP := 'AV' || TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- DATABASE_COLUMN_TEMP;
- L_VAL_COL := 'AV' || TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- C_COL.DATABASE_COLUMN;
- L_UOM_COL_TEMP := REPLACE(L_VAL_COL_TEMP, 'N', 'UOM');
- L_UOM_COL := REPLACE(L_VAL_COL, 'N', 'UOM');
- DBMS_LOB.APPEND(V_QUERY1,
- '
- CASE WHEN (XXRSV_ENDECA_PKG.GET_STR_FEATURE(' ||
- L_VAL_COL || ', ' || L_UOM_COL ||
- ') IS NULL AND XXRSV_ENDECA_PKG.GET_STR_FEATURE(' ||
- L_VAL_COL_TEMP || ', ' || L_UOM_COL_TEMP ||
- ') IS NOT NULL) THEN XXRSV_ENDECA_PKG.GET_STR_FEATURE(' ||
- L_VAL_COL_TEMP || ', ' || L_UOM_COL_TEMP ||
- ') WHEN (XXRSV_ENDECA_PKG.GET_STR_FEATURE(' ||
- L_VAL_COL || ', ' || L_UOM_COL ||
- ') IS NOT NULL AND XXRSV_ENDECA_PKG.GET_STR_FEATURE(' ||
- L_VAL_COL_TEMP || ', ' || L_UOM_COL_TEMP ||
- ') IS NULL) THEN XXRSV_ENDECA_PKG.GET_STR_FEATURE(' ||
- L_VAL_COL || ', ' || L_UOM_COL ||
- ') WHEN (XXRSV_ENDECA_PKG.GET_STR_FEATURE(' ||
- L_VAL_COL || ', ' || L_UOM_COL ||
- ') IS NULL AND XXRSV_ENDECA_PKG.GET_STR_FEATURE(' ||
- L_VAL_COL_TEMP || ', ' || L_UOM_COL_TEMP ||
- ') IS NULL) THEN ''Не определено''
- ELSE (XXRSV_ENDECA_PKG.GET_STR_FEATURE(' ||
- L_VAL_COL || ', ' || L_UOM_COL ||
- ') || '' - '' || XXRSV_ENDECA_PKG.GET_STR_FEATURE(' ||
- L_VAL_COL_TEMP || ', ' || L_UOM_COL_TEMP ||
- ')) END AS ' || 'tech_' || C_COL.ATTR_NAME);
- ELSE
- DBMS_LOB.APPEND(V_QUERY1,
- '
- CASE WHEN (AV' || TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- C_COL.DATABASE_COLUMN || ' IS NULL AND AV' ||
- TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- DATABASE_COLUMN_TEMP || ' IS NOT NULL) THEN AV' ||
- TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- DATABASE_COLUMN_TEMP || ' WHEN (AV' ||
- TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- C_COL.DATABASE_COLUMN || ' IS NOT NULL AND AV' ||
- TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- DATABASE_COLUMN_TEMP || ' IS NULL) THEN AV' ||
- TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- C_COL.DATABASE_COLUMN || ' WHEN (AV' ||
- TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- C_COL.DATABASE_COLUMN || ' IS NULL AND AV' ||
- TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- DATABASE_COLUMN_TEMP ||
- ' IS NULL) THEN ''Не определено''
- ELSE (AV' ||
- TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- C_COL.DATABASE_COLUMN || ' || '' - '' || AV' ||
- TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- DATABASE_COLUMN_TEMP || ') END AS ' || 'tech_' ||
- C_COL.ATTR_NAME);
- END IF;
- DATABASE_COLUMN_TEMP := '';
- DATA_TYPE_TEMP := '';
- L_UOM_COL_TEMP := '';
- L_UOM_COL := '';
- END IF;
- --END OF COMBINING--------------------------------------------------
- ELSE
- IF C_COL.DATA_TYPE = 'N' THEN
- DBMS_LOB.APPEND(V_QUERY1,
- '
- NVL(XXRSV_RS24_TECH_SPEC_UOM.GET_ATTR_VAL_WITH_UOM_DEF(P_ITEM_ID => P.ITEM_ID,
- P_ORG_ID => XXRSV_GLOBALS.GET_MAIN_ORG_ID,
- P_GROUP_NAME => ''' ||
- C_COL.ATTR_GROUP_NAME || ''',
- P_ATTR_NAME => ''' ||
- C_COL.ATTR_NAME || '''), ''Не определено'') AS ' ||
- 'tech_' || C_COL.ATTR_NAME);
- ELSE
- DBMS_LOB.APPEND(V_QUERY1,
- '
- NVL(AV' || TO_CHAR(L_ATTR_GROUP_ID_STR) || '.' ||
- C_COL.DATABASE_COLUMN ||
- ', ''Не определено'') AS ' || 'tech_' ||
- C_COL.ATTR_NAME);
- END IF;
- END IF;
- END LOOP;
- DBMS_LOB.APPEND(V_QUERY11,
- 'SELECT P.ITEM_ID,
- P.ITEM_CODE,
- P.VENDOR_ARTICLE,
- P.BRAND,
- P.UOM,
- P.PRIMARY_UNIT_OF_MEASURE,
- P.PRODUCT_DESCRIPTION,
- P.PRODUCT_LONG_DESCRIPTION,
- P.SERIES,
- P.VENDOR_DESCRIPTION,
- P.ITEM_CATALOG_GROUP_ID,
- P.IMAGE,
- PI.LOYALTY_PROG,
- PI.KOD_MINPROMTORG,
- PI.IN_STOCK,
- PI.BARCODE,
- PP.PRICE_1,
- PP.PRICE_2,
- PP.PRICE_3,
- PPR.DEAL_NAME,
- PPR.DEAL_USER_TYPE,
- PAC.CAT_CW_TV,
- PAC.CAT_CW_TUL,
- PAC.CAT_CW_ROS,
- PAC.CAT_CW_SAM,
- PAC.CAT_CW_SIB,
- PAC.CAT_CW_UR,
- PM.MULTIPLICITY_TV,
- PM.MULTIPLICITY_TUL,
- PM.MULTIPLICITY_ROS,
- PM.MULTIPLICITY_SAM,
- PM.MULTIPLICITY_SIB,
- PM.MULTIPLICITY_UR,
- PQ.QUANTITY_TV,
- PQ.QUANTITY_SAM,
- PQ.QUANTITY_ROS,
- PQ.QUANTITY_SIB,
- PQ.QUANTITY_TUL,
- PQ.QUANTITY_UR,
- NVL2(PS.SALES_TV, ''Y'', ''N'') AS SALES_TV,
- NVL2(PS.SALES_SAM, ''Y'', ''N'') AS SALES_SAM,
- NVL2(PS.SALES_ROS, ''Y'', ''N'') AS SALES_ROS,
- NVL2(PS.SALES_SIB, ''Y'', ''N'') AS SALES_SIB,
- NVL2(PS.SALES_TUL, ''Y'', ''N'') AS SALES_TUL,
- NVL2(PS.SALES_UR, ''Y'', ''N'') AS SALES_UR');
- DBMS_LOB.APPEND(V_QUERY11, V_QUERY1);
- DBMS_LOB.APPEND(V_QUERY11,
- '
- FROM ' || V_QUERY_TAB || '
- RS24_PRODUCT_MV P,
- RS24_PRODUCT_ANALITIC_CAT_MV PAC,
- RS24_PRODUCT_MULTIPLICITY_MV PM,
- RS24_PRODUCT_QUANTITY_MV PQ,
- RS24_PRODUCT_INFO_MV PI,
- RS24_PRODUCT_PRICE_V PP,
- RS24_PRODUCT_PROMOS_V PPR,
- RS24_PRODUCT_SALES_V PS
- WHERE 1 = 1
- AND P.ITEM_ID = PAC.ITEM_ID(+)
- AND P.ITEM_ID = PM.ITEM_ID(+)
- AND P.ITEM_ID = PQ.ITEM_ID(+)
- AND P.ITEM_ID = PI.ITEM_ID(+)
- AND P.ITEM_ID = PP.ITEM_ID(+)
- AND P.ITEM_ID = PPR.ITEM_ID(+)
- AND P.ITEM_ID = PS.ITEM_ID(+)
- AND PAC.CAT_CW_TV IS NOT NULL
- AND PAC.CAT_CW_TUL IS NOT NULL
- AND PAC.CAT_CW_ROS IS NOT NULL
- AND PAC.CAT_CW_SAM IS NOT NULL
- AND PAC.CAT_CW_SIB IS NOT NULL
- AND PAC.CAT_CW_UR IS NOT NULL
- AND P.ITEM_CATALOG_GROUP_ID = ' ||
- L_ITEM_CATALOG_GROUP_ID || V_QUERY_WHERE);
- DBMS_LOB.APPEND(V_QUERY, V_QUERY11);
- RETURN V_QUERY;
- END TEXT_QUERY;
- FUNCTION GET_STR_FEATURE(P_N_EXT_ATTR NUMBER, P_UOM_EXT_ATTR VARCHAR2)
- RETURN VARCHAR2 IS
- L_STR_FEATURE VARCHAR2(240);
- --TEMP1 NUMBER;
- TEMP VARCHAR2(240);
- TEMPN VARCHAR2(240);
- BEGIN
- /* BEGIN
- SELECT DECODE(INV_CONVERT.INV_UM_CONVERT(0,
- 5,
- P_N_EXT_ATTR,
- (SELECT TT.UOM_CODE
- FROM MTL_UNITS_OF_MEASURE_VL TT,
- MTL_UNITS_OF_MEASURE_VL T
- WHERE TT.UOM_CLASS =
- T.UOM_CLASS
- AND T.UOM_CODE =
- P_UOM_EXT_ATTR
- AND TT.BASE_UOM_FLAG = 'Y'),
- P_UOM_EXT_ATTR,
- NULL,
- NULL),
- -99999,
- P_N_EXT_ATTR)
- INTO TEMP1
- FROM DUAL;
- EXCEPTION
- WHEN OTHERS THEN
- TEMP1 := NULL;
- END;
- */
- IF (P_N_EXT_ATTR IS NULL) THEN
- RETURN NULL;
- ELSE
- BEGIN
- SELECT T.UNIT_OF_MEASURE
- INTO TEMP
- FROM MTL_UNITS_OF_MEASURE_VL T
- WHERE T.UOM_CODE = P_UOM_EXT_ATTR;
- EXCEPTION
- WHEN OTHERS THEN
- TEMP := NULL;
- END;
- TEMPN := RTRIM(TO_CHAR(P_N_EXT_ATTR,
- 'FM9999999999999999990D9999999999999999999',
- 'NLS_NUMERIC_CHARACTERS = ''. '''),
- '.');
- IF (TEMP IS NULL) THEN
- L_STR_FEATURE := TEMPN;
- ELSE
- L_STR_FEATURE := TEMPN || ' ' || TEMP;
- END IF;
- END IF;
- RETURN L_STR_FEATURE;
- END GET_STR_FEATURE;
- FUNCTION GET_ITEM_IMAGE(P_ORGANIZATION_ID NUMBER,
- P_INVENTORY_ITEM_ID NUMBER) RETURN VARCHAR2 IS
- IMG_RES VARCHAR2(240);
- BEGIN
- BEGIN
- SELECT T.URL AS FILE_NAME
- INTO IMG_RES
- FROM (SELECT A.URL
- FROM APPS.FND_ATTACHED_DOCS_FORM_VL A
- WHERE FUNCTION_NAME = 'INVIDITM'
- AND FUNCTION_TYPE = 'O'
- AND (SECURITY_TYPE = 4 OR PUBLISH_FLAG = 'Y' OR
- (SECURITY_TYPE = 1))
- AND (ENTITY_NAME = 'MTL_SYSTEM_ITEMS' AND
- PK1_VALUE = TO_CHAR(P_ORGANIZATION_ID))
- AND CATEGORY_ID = 34
- AND DATATYPE_ID = 5
- AND PK2_VALUE = TO_CHAR(P_INVENTORY_ITEM_ID)
- AND LOWER(SUBSTR(A.URL, INSTR(A.URL, '.', -1))) IN
- ('.jpg', '.jpeg', '.png', '.gif', '.bmp')
- ORDER BY A.SEQ_NUM) T
- WHERE ROWNUM = 1;
- EXCEPTION
- WHEN NO_DATA_FOUND THEN
- IMG_RES := 'no_image.jpg';
- END;
- RETURN IMG_RES;
- EXCEPTION
- WHEN OTHERS THEN
- RETURN '';
- END GET_ITEM_IMAGE;
- END RS24_CATALOG_BUILDER_PKG;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement