DECLARE
CURSOR C1 IS
SELECT *
FROM XX_UPLOAD_AR_INVOICES ar
WHERE ar.PROCESS_FLAG IS NULL
AND ar.SR_NO IN (3,4) ;
v_trx_type NUMBER;
v_trx_name VARCHAR2(60);
v_batch_id NUMBER;
v_batch_name VARCHAR2(60);
v_gl_id NUMBER;
v_customer_id NUMBER;
v_bill_to_address_id NUMBER;
v_ship_to_address_id NUMBER;
V_TERM_ID NUMBER;
V_TERM VARCHAR2(50);
V_CC NUMBER;
V_ERR VARCHAR2(4000);
V_SITE VARCHAr2(150);
V_INTERFACE_LINE_ID NUMBER;
BEGIN
FOR i IN C1
LOOP
V_ERR := Null;
BEGIN
/* ---- Check Batch Source Name ------ */
SELECT rb.BATCH_SOURCE_ID, rb.NAME
INTO v_batch_id, v_batch_name
FROM RA_BATCH_SOURCES_ALL rb
WHERE rb.NAME = 'Open Data Import Source'
AND rb.ORG_ID = 82 ;
/* ----- Check Transaction Type -----*/
SELECT rct.CUST_TRX_TYPE_ID, rct.NAME, rct.SET_OF_BOOKS_ID
INTO v_trx_type, v_trx_name, v_gl_id
FROM RA_CUST_TRX_TYPES_ALL rct
WHERE rct.NAME = 'NEEPL_MCS_DOM_INV' --- ar.CLASS
AND rct.ORG_ID = 82 ;
/* ----- Check Term Information ------ */
BEGIN
SELECT rt.TERM_ID, rt.NAME INTO V_TERM_ID, V_TERM
FROM RA_TERMS rt
WHERE UPPER(rt.NAME) = UPPER( i.PAYMENT_TERM );
EXCEPTION
WHEN OTHERS THEN
V_TERM_ID := 5;
END;
BEGIN
SELECT hca.CUST_ACCOUNT_ID INTO v_customer_id
FROM HZ_PARTIES hp,
HZ_CUST_ACCOUNTS hca
WHERE hp.PARTY_ID = hca.PARTY_ID
AND UPPER(RTRIM(LTRIM(hp.PARTY_NAME))) = UPPER(RTRIM(LTRIM(i.BILL_TO_NAME)));
EXCEPTION
WHEN OTHERS THEN
v_customer_id := NULL;
V_ERR := V_ERR || ' Supplier Not Exists.';
END;
/* ----- Bill to address id ------ */
BEGIN
SELECT hcas.CUST_ACCT_SITE_ID INTO v_bill_to_address_id
FROM hz_cust_accounts_all hca
,hz_cust_acct_sites_all hcas
,hz_cust_site_uses_all hcsu
WHERE 1 = 1
AND hca.cust_account_id = hcas.cust_account_id
AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
AND hcsu.status = 'A'
AND hcsu.site_use_code = 'BILL_TO'
AND hca.cust_account_id = v_customer_id
AND hcsu.org_id = 82;
EXCEPTION
WHEN OTHERS THEN
v_bill_to_address_id := NULL;
V_ERR := V_ERR || ' Bill to Addrees not exist';
END;
BEGIN
/* ----- Ship to Address ID ------ */
SELECT hcas.CUST_ACCT_SITE_ID INTO v_ship_to_address_id
FROM hz_cust_accounts_all hca
,hz_cust_acct_sites_all hcas
,hz_cust_site_uses_all hcsu
WHERE 1 = 1
AND hca.cust_account_id = hcas.cust_account_id
AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
AND hcsu.status = 'A'
AND hcsu.site_use_code = 'SHIP_TO'
AND hca.cust_account_id = v_customer_id
AND hcsu.org_id = 82;
EXCEPTION
WHEN OTHERS THEN
v_ship_to_address_id := NULL;
END;
IF v_customer_id IS NOT NULL AND v_bill_to_address_id IS NOT NULL THEN
SELECT RA_CUSTOMER_TRX_LINES_S.NEXTVAL INTO V_INTERFACE_LINE_ID
FROM DUAL;
BEGIN
SELECT ffv.FLEX_VALUE INTO V_SITE
FROM FND_FLEX_VALUES_VL ffv
WHERE ffv.FLEX_VALUE_SET_ID = 1014868
AND UPPER(ffv.DESCRIPTION) = UPPER(i.SITE) ;
EXCEPTION
WHEN OTHERS THEN
V_SITE := NULL;
END;
INSERT INTO ra_interface_lines_all ria
( INTERFACE_LINE_ID,BATCH_SOURCE_NAME,LINE_TYPE,
ria.TRX_NUMBER,
CUST_TRX_TYPE_ID,
cust_trx_type_name,
SET_OF_BOOKS_ID,
TRX_DATE,
GL_DATE,
CURRENCY_CODE,
term_id,
term_name,
orig_system_bill_customer_id,
ORIG_SYSTEM_BILL_CUSTOMER_REF,
orig_system_bill_address_id,
ORIG_SYSTEM_BILL_ADDRESS_REF,
ria.ORIG_SYSTEM_SHIP_ADDRESS_ID,
ria.ORIG_SYSTEM_SHIP_ADDRESS_REF,
ria.INVENTORY_ITEM_ID,
QUANTITY,
ria.UNIT_SELLING_PRICE,
AMOUNT,
DESCRIPTION,
org_id,
CONVERSION_TYPE,
ria.CONVERSION_RATE,
ria.INTERFACE_LINE_CONTEXT,
ria.INTERFACE_LINE_ATTRIBUTE1,
ria.INTERFACE_LINE_ATTRIBUTE2,
ria.INTERFACE_LINE_ATTRIBUTE3,
ria.INTERFACE_LINE_ATTRIBUTE4,
ria.INTERFACE_LINE_ATTRIBUTE5,
ria.INTERFACE_LINE_ATTRIBUTE6,
ria.INTERFACE_LINE_ATTRIBUTE7,
ria.INTERFACE_LINE_ATTRIBUTE8,
ria.INTERFACE_LINE_ATTRIBUTE9,
ria.INTERFACE_LINE_ATTRIBUTE10,
ria.INTERFACE_LINE_ATTRIBUTE11,
ria.INTERFACE_LINE_ATTRIBUTE12,
ria.INTERFACE_LINE_ATTRIBUTE13,
ria.INTERFACE_LINE_ATTRIBUTE14,
ria.INTERFACE_LINE_ATTRIBUTE15,
ria.PRIMARY_SALESREP_NUMBER,
ria.HEADER_ATTRIBUTE1,
ria.HEADER_ATTRIBUTE2,
ria.HEADER_ATTRIBUTE3
)Values
(V_INTERFACE_LINE_ID,
'Open Data Import Source',
'LINE',
NULL,
v_trx_type, -- cust_trx_type_id,
'NEEPL_MCS_DOM_INV', -- cust_trx_type_name,
v_gl_id,
i.INV_DATE ,
'28-FEB-2013',
'INR', -- currency_code,
V_TERM_ID, -- term_id,
V_TERM, -- term_name,
v_customer_id,
v_customer_id,
v_bill_to_address_id,
v_bill_to_address_id,
v_ship_to_address_id,
v_ship_to_address_id,
NULL, --- Inventory item id
1, --- Qty
i.AMOUNT, --- Unit Selling Price
i.AMOUNT, --- Invoice Amount
'Test Invoice', --- Description
82, --- Orgid
'User', --- Conversion Type
1, --- Convesrion rate
'ORDER ENTRY',
i.BILL_TO_NUMBER ,
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
-3, ---primary saleperson -- No Sales Credits
i.DIVISION,
V_SITE,
i.BILL_TO_NUMBER
);
COMMIT;
BEGIN
SELECT gcc.CODE_COMBINATION_ID INTO V_CC
FROM GL_CODE_COMBINATIONS gcc
WHERE gcc.SEGMENT1||'.'||gcc.SEGMENT2||'.'||
gcc.SEGMENT3||'.'||gcc.SEGMENT4||'.'||gcc.SEGMENT5||'.'||
gcc.SEGMENT6||'.'||gcc.SEGMENT7||'.'||gcc.SEGMENT8 = TRIM(i.ACCOUNT_CODE);
EXCEPTION
WHEN OTHERS THEN
V_CC := NULL;
END;
INSERT INTO ra_interface_distributions_all rid
(
INTERFACE_LINE_ID
,account_class
,amount
,code_combination_id
,percent
,org_id
)
VALUES
(
V_INTERFACE_LINE_ID,
'REV'
,i.AMOUNT --- Invoice Amt
,V_CC --- Code Combination ID
,100
,82
);
COMMIT;
INSERT INTO RA_INTERFACE_SALESCREDITS_ALL rs
(rs.INTERFACE_LINE_ID,
rs.INTERFACE_LINE_CONTEXT,
rs.INTERFACE_LINE_ATTRIBUTE1,
rs.INTERFACE_LINE_ATTRIBUTE2,
rs.INTERFACE_LINE_ATTRIBUTE3,
rs.INTERFACE_LINE_ATTRIBUTE4,
rs.INTERFACE_LINE_ATTRIBUTE5,
rs.INTERFACE_LINE_ATTRIBUTE6,
rs.INTERFACE_LINE_ATTRIBUTE7,
rs.INTERFACE_LINE_ATTRIBUTE8,
rs.INTERFACE_LINE_ATTRIBUTE9,
rs.INTERFACE_LINE_ATTRIBUTE10,
rs.INTERFACE_LINE_ATTRIBUTE11,
rs.INTERFACE_LINE_ATTRIBUTE12,
rs.INTERFACE_LINE_ATTRIBUTE13,
rs.INTERFACE_LINE_ATTRIBUTE14,
rs.INTERFACE_LINE_ATTRIBUTE15,
rs.CREATION_DATE,
rs.CREATED_BY,
rs.SALES_CREDIT_AMOUNT_SPLIT,
rs.SALES_CREDIT_PERCENT_SPLIT,
rs.SALESREP_NUMBER,
rs.SALESREP_ID,
rs.SALES_CREDIT_TYPE_ID,
rs.SALES_CREDIT_TYPE_NAME,
rs.ORG_ID )
VALUES
(V_INTERFACE_LINE_ID,
'ORDER ENTRY',
i.BILL_TO_NUMBER,
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
SYSDATE,
1110,
i.AMOUNT, -- Amount
100,
-3,
NULL,
1,
'Quota Sales Credit',
82
);
COMMIT;
UPDATE XX_UPLOAD_AR_INVOICES ar
SET ar.PROCESS_FLAG = 'Y'
, ar.ERROR_MESSAGE = NULL
WHERE ar.SR_NO = i.SR_NO;
COMMIT;
ELSE
UPDATE XX_UPLOAD_AR_INVOICES ar
SET ar.PROCESS_FLAG = 'E'
, ar.ERROR_MESSAGE = V_ERR
WHERE ar.SR_NO = i.SR_NO;
COMMIT;
END IF;
EXCEPTION
WHEN OTHERS THEN
V_ERR := SQLCODE || '-'|| SQLERRM;
UPDATE XX_UPLOAD_AR_INVOICES ar
SET ar.PROCESS_FLAG = 'EE'
, ar.ERROR_MESSAGE = V_ERR
WHERE ar.SR_NO = i.SR_NO;
COMMIT;
END;
END LOOP;
END;
CURSOR C1 IS
SELECT *
FROM XX_UPLOAD_AR_INVOICES ar
WHERE ar.PROCESS_FLAG IS NULL
AND ar.SR_NO IN (3,4) ;
v_trx_type NUMBER;
v_trx_name VARCHAR2(60);
v_batch_id NUMBER;
v_batch_name VARCHAR2(60);
v_gl_id NUMBER;
v_customer_id NUMBER;
v_bill_to_address_id NUMBER;
v_ship_to_address_id NUMBER;
V_TERM_ID NUMBER;
V_TERM VARCHAR2(50);
V_CC NUMBER;
V_ERR VARCHAR2(4000);
V_SITE VARCHAr2(150);
V_INTERFACE_LINE_ID NUMBER;
BEGIN
FOR i IN C1
LOOP
V_ERR := Null;
BEGIN
/* ---- Check Batch Source Name ------ */
SELECT rb.BATCH_SOURCE_ID, rb.NAME
INTO v_batch_id, v_batch_name
FROM RA_BATCH_SOURCES_ALL rb
WHERE rb.NAME = 'Open Data Import Source'
AND rb.ORG_ID = 82 ;
/* ----- Check Transaction Type -----*/
SELECT rct.CUST_TRX_TYPE_ID, rct.NAME, rct.SET_OF_BOOKS_ID
INTO v_trx_type, v_trx_name, v_gl_id
FROM RA_CUST_TRX_TYPES_ALL rct
WHERE rct.NAME = 'NEEPL_MCS_DOM_INV' --- ar.CLASS
AND rct.ORG_ID = 82 ;
/* ----- Check Term Information ------ */
BEGIN
SELECT rt.TERM_ID, rt.NAME INTO V_TERM_ID, V_TERM
FROM RA_TERMS rt
WHERE UPPER(rt.NAME) = UPPER( i.PAYMENT_TERM );
EXCEPTION
WHEN OTHERS THEN
V_TERM_ID := 5;
END;
BEGIN
SELECT hca.CUST_ACCOUNT_ID INTO v_customer_id
FROM HZ_PARTIES hp,
HZ_CUST_ACCOUNTS hca
WHERE hp.PARTY_ID = hca.PARTY_ID
AND UPPER(RTRIM(LTRIM(hp.PARTY_NAME))) = UPPER(RTRIM(LTRIM(i.BILL_TO_NAME)));
EXCEPTION
WHEN OTHERS THEN
v_customer_id := NULL;
V_ERR := V_ERR || ' Supplier Not Exists.';
END;
/* ----- Bill to address id ------ */
BEGIN
SELECT hcas.CUST_ACCT_SITE_ID INTO v_bill_to_address_id
FROM hz_cust_accounts_all hca
,hz_cust_acct_sites_all hcas
,hz_cust_site_uses_all hcsu
WHERE 1 = 1
AND hca.cust_account_id = hcas.cust_account_id
AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
AND hcsu.status = 'A'
AND hcsu.site_use_code = 'BILL_TO'
AND hca.cust_account_id = v_customer_id
AND hcsu.org_id = 82;
EXCEPTION
WHEN OTHERS THEN
v_bill_to_address_id := NULL;
V_ERR := V_ERR || ' Bill to Addrees not exist';
END;
BEGIN
/* ----- Ship to Address ID ------ */
SELECT hcas.CUST_ACCT_SITE_ID INTO v_ship_to_address_id
FROM hz_cust_accounts_all hca
,hz_cust_acct_sites_all hcas
,hz_cust_site_uses_all hcsu
WHERE 1 = 1
AND hca.cust_account_id = hcas.cust_account_id
AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
AND hcsu.status = 'A'
AND hcsu.site_use_code = 'SHIP_TO'
AND hca.cust_account_id = v_customer_id
AND hcsu.org_id = 82;
EXCEPTION
WHEN OTHERS THEN
v_ship_to_address_id := NULL;
END;
IF v_customer_id IS NOT NULL AND v_bill_to_address_id IS NOT NULL THEN
SELECT RA_CUSTOMER_TRX_LINES_S.NEXTVAL INTO V_INTERFACE_LINE_ID
FROM DUAL;
BEGIN
SELECT ffv.FLEX_VALUE INTO V_SITE
FROM FND_FLEX_VALUES_VL ffv
WHERE ffv.FLEX_VALUE_SET_ID = 1014868
AND UPPER(ffv.DESCRIPTION) = UPPER(i.SITE) ;
EXCEPTION
WHEN OTHERS THEN
V_SITE := NULL;
END;
INSERT INTO ra_interface_lines_all ria
( INTERFACE_LINE_ID,BATCH_SOURCE_NAME,LINE_TYPE,
ria.TRX_NUMBER,
CUST_TRX_TYPE_ID,
cust_trx_type_name,
SET_OF_BOOKS_ID,
TRX_DATE,
GL_DATE,
CURRENCY_CODE,
term_id,
term_name,
orig_system_bill_customer_id,
ORIG_SYSTEM_BILL_CUSTOMER_REF,
orig_system_bill_address_id,
ORIG_SYSTEM_BILL_ADDRESS_REF,
ria.ORIG_SYSTEM_SHIP_ADDRESS_ID,
ria.ORIG_SYSTEM_SHIP_ADDRESS_REF,
ria.INVENTORY_ITEM_ID,
QUANTITY,
ria.UNIT_SELLING_PRICE,
AMOUNT,
DESCRIPTION,
org_id,
CONVERSION_TYPE,
ria.CONVERSION_RATE,
ria.INTERFACE_LINE_CONTEXT,
ria.INTERFACE_LINE_ATTRIBUTE1,
ria.INTERFACE_LINE_ATTRIBUTE2,
ria.INTERFACE_LINE_ATTRIBUTE3,
ria.INTERFACE_LINE_ATTRIBUTE4,
ria.INTERFACE_LINE_ATTRIBUTE5,
ria.INTERFACE_LINE_ATTRIBUTE6,
ria.INTERFACE_LINE_ATTRIBUTE7,
ria.INTERFACE_LINE_ATTRIBUTE8,
ria.INTERFACE_LINE_ATTRIBUTE9,
ria.INTERFACE_LINE_ATTRIBUTE10,
ria.INTERFACE_LINE_ATTRIBUTE11,
ria.INTERFACE_LINE_ATTRIBUTE12,
ria.INTERFACE_LINE_ATTRIBUTE13,
ria.INTERFACE_LINE_ATTRIBUTE14,
ria.INTERFACE_LINE_ATTRIBUTE15,
ria.PRIMARY_SALESREP_NUMBER,
ria.HEADER_ATTRIBUTE1,
ria.HEADER_ATTRIBUTE2,
ria.HEADER_ATTRIBUTE3
)Values
(V_INTERFACE_LINE_ID,
'Open Data Import Source',
'LINE',
NULL,
v_trx_type, -- cust_trx_type_id,
'NEEPL_MCS_DOM_INV', -- cust_trx_type_name,
v_gl_id,
i.INV_DATE ,
'28-FEB-2013',
'INR', -- currency_code,
V_TERM_ID, -- term_id,
V_TERM, -- term_name,
v_customer_id,
v_customer_id,
v_bill_to_address_id,
v_bill_to_address_id,
v_ship_to_address_id,
v_ship_to_address_id,
NULL, --- Inventory item id
1, --- Qty
i.AMOUNT, --- Unit Selling Price
i.AMOUNT, --- Invoice Amount
'Test Invoice', --- Description
82, --- Orgid
'User', --- Conversion Type
1, --- Convesrion rate
'ORDER ENTRY',
i.BILL_TO_NUMBER ,
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
-3, ---primary saleperson -- No Sales Credits
i.DIVISION,
V_SITE,
i.BILL_TO_NUMBER
);
COMMIT;
BEGIN
SELECT gcc.CODE_COMBINATION_ID INTO V_CC
FROM GL_CODE_COMBINATIONS gcc
WHERE gcc.SEGMENT1||'.'||gcc.SEGMENT2||'.'||
gcc.SEGMENT3||'.'||gcc.SEGMENT4||'.'||gcc.SEGMENT5||'.'||
gcc.SEGMENT6||'.'||gcc.SEGMENT7||'.'||gcc.SEGMENT8 = TRIM(i.ACCOUNT_CODE);
EXCEPTION
WHEN OTHERS THEN
V_CC := NULL;
END;
INSERT INTO ra_interface_distributions_all rid
(
INTERFACE_LINE_ID
,account_class
,amount
,code_combination_id
,percent
,org_id
)
VALUES
(
V_INTERFACE_LINE_ID,
'REV'
,i.AMOUNT --- Invoice Amt
,V_CC --- Code Combination ID
,100
,82
);
COMMIT;
INSERT INTO RA_INTERFACE_SALESCREDITS_ALL rs
(rs.INTERFACE_LINE_ID,
rs.INTERFACE_LINE_CONTEXT,
rs.INTERFACE_LINE_ATTRIBUTE1,
rs.INTERFACE_LINE_ATTRIBUTE2,
rs.INTERFACE_LINE_ATTRIBUTE3,
rs.INTERFACE_LINE_ATTRIBUTE4,
rs.INTERFACE_LINE_ATTRIBUTE5,
rs.INTERFACE_LINE_ATTRIBUTE6,
rs.INTERFACE_LINE_ATTRIBUTE7,
rs.INTERFACE_LINE_ATTRIBUTE8,
rs.INTERFACE_LINE_ATTRIBUTE9,
rs.INTERFACE_LINE_ATTRIBUTE10,
rs.INTERFACE_LINE_ATTRIBUTE11,
rs.INTERFACE_LINE_ATTRIBUTE12,
rs.INTERFACE_LINE_ATTRIBUTE13,
rs.INTERFACE_LINE_ATTRIBUTE14,
rs.INTERFACE_LINE_ATTRIBUTE15,
rs.CREATION_DATE,
rs.CREATED_BY,
rs.SALES_CREDIT_AMOUNT_SPLIT,
rs.SALES_CREDIT_PERCENT_SPLIT,
rs.SALESREP_NUMBER,
rs.SALESREP_ID,
rs.SALES_CREDIT_TYPE_ID,
rs.SALES_CREDIT_TYPE_NAME,
rs.ORG_ID )
VALUES
(V_INTERFACE_LINE_ID,
'ORDER ENTRY',
i.BILL_TO_NUMBER,
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
SYSDATE,
1110,
i.AMOUNT, -- Amount
100,
-3,
NULL,
1,
'Quota Sales Credit',
82
);
COMMIT;
UPDATE XX_UPLOAD_AR_INVOICES ar
SET ar.PROCESS_FLAG = 'Y'
, ar.ERROR_MESSAGE = NULL
WHERE ar.SR_NO = i.SR_NO;
COMMIT;
ELSE
UPDATE XX_UPLOAD_AR_INVOICES ar
SET ar.PROCESS_FLAG = 'E'
, ar.ERROR_MESSAGE = V_ERR
WHERE ar.SR_NO = i.SR_NO;
COMMIT;
END IF;
EXCEPTION
WHEN OTHERS THEN
V_ERR := SQLCODE || '-'|| SQLERRM;
UPDATE XX_UPLOAD_AR_INVOICES ar
SET ar.PROCESS_FLAG = 'EE'
, ar.ERROR_MESSAGE = V_ERR
WHERE ar.SR_NO = i.SR_NO;
COMMIT;
END;
END LOOP;
END;
No comments:
Post a Comment