Sunteți pe pagina 1din 8

CREATE OR REPLACE PACKAGE XX_AR_INVOICE_IMP_PKG AS

PROCEDURE XX_AR_INVOICE_IMP_PROC(ERRBUF OUT VARCHAR2,RETCODE OUT NUMBER);


END XX_AR_INVOICE_IMP_PKG;
/
================================================================================
===============
================================================================================
===============

CREATE OR REPLACE PACKAGE BODY XX_AR_INVOICE_IMP_PKG AS


PROCEDURE XX_AR_INVOICE_IMP_PROC(ERRBUF OUT VARCHAR2,RETCODE OUT NUMBER) IS
CURSOR C IS SELECT a.rowid,a.*
FROM XX_AR_INVOICE_STG a
WHERE a.STATUS_FLAG='N';

l_flag varchar2(1);
l_currency_code varchar2(5);
l_CUST_TRX_TYPE_ID number;
err_msg varchar2(2000);
L_batch_source_id varchar2(30);
L_tax_id varchar2(30);
L_cust_number varchar2(50);
l_cust_bill_add_id varchar2(50);
l_cust_ship_add_id varchar2(50);
l_sequence_no number;
l_attri2 varchar2(50);
L_term_id varchar2(10);
l_cust_account_id varchar2(10);
L_uom varchar2(10);
l_interface_line_attribute1 varchar2(120);
l_convertion_type varchar2(100);
l_set_of_books_id number;
L_INVENTORY_ITEM_ID number;
org_id number;
L_CONVERSION_RATE number;
l_account_number number;

begin
for i in c loop
l_flag:='Y';

--- uom validation

BEGIN
SELECT UOM_CODE INTO L_uom
FROM MTL_UNITS_OF_MEASURE
WHERE trim(UOM_CODE)=trim(i.UOM);
exception
when others then
l_flag:='E';
err_msg:=err_msg||'uom code Is Not Existing'||'/';
end;

-- Currency validation

BEGIN
SELECT CURRENCY_CODE
INTO L_CURRENCY_CODE
FROM FND_CURRENCIES
WHERE trim(CURRENCY_CODE)=trim(I.INVOICE_CURRENCY);
EXCEPTION
WHEN OTHERS THEN
L_FLAG:='E';
ERR_MSG:=ERR_MSG||'Invalid Currency '||'/';
END;

-- Getting Conversion Rate


BEGIN
IF L_CURRENCY_CODE ='KES' THEN
L_CONVERSION_RATE:=1;
ELSE
L_CONVERSION_RATE:=I.CONVERSION_RATE;
END IF;
END;
-- To get org_id
begin
SELECT ORGANIZATION_ID INTO org_id
from hr_operating_units where NAME=i.OPERATING_UNIT;
exception
when others then
l_flag:='E';
err_msg:=err_msg||'operating unit Is Not Existing'||'/'
;
end;

-- TO GET CUST ID
begin
select cust_account_id,account_number
into l_cust_account_id,l_account_number
from hz_cust_accounts hca,hz_parties hp
where account_number =C1.CUSTOMER_NUMBER
and hp.party_id=hca.party_id;
exception
when others then
l_flag:='E';
err_msg:=err_msg||'Cust Account No Is Not Existing'||'/';
end;
-- to get bill to address id

begin
SELECT HCSUA.cust_acct_site_id
INTO l_cust_bill_add_id
FROM hz_cust_acct_sites_all HCASA,
hz_cust_site_uses_all HCSUA
WHERE cust_account_id=(SELECT cust_account_id FROM hz_cust_accounts
HCA, hz_parties HP
WHERE account_number=l_account_number AND hp.party_id=hca.party_id)
AND hcasa.cust_acct_site_id=hcsua.cust_acct_site_id
AND site_use_code='BILL_TO';
-- AND HCSUA.SITE_USE_ID=i.ORACLE_BILL_TO ;
exception
when others then
l_flag:='E';
err_msg:=err_msg||'Cust Account Site id BILL_TO Is Not Existing'||'/
';
end;
DBMS_OUTPUT.PUT_LINE('BILL TO ADDRESS ID'||l_cust_bill_add_id);

-- to get SHIP to address id


begin
SELECT HCSUA.cust_acct_site_id
INTO l_cust_ship_add_id
FROM hz_cust_acct_sites_all HCASA,hz_cust_site_uses_all HCSUA
WHERE cust_account_id=(SELECT cust_account_id FROM hz_cust_accounts HCA,
hz_parties HP
WHERE account_number=l_account_number AND hp.party_id=hca.party_id)
AND hcasa.cust_acct_site_id=hcsua.cust_acct_site_id
AND site_use_code='SHIP_TO';
-- AND HCSUA.SITE_USE_ID=i.ORACLE_SHIP_TO ;
exception
when others then
l_flag:='E';
err_msg:=err_msg||'Cust Account Site id SHIP_TO Is Not Existing'||'/';
end;

--toget payment term ID


BEGIN
SELECT term_id INTO L_term_id
FROM ra_terms_tl
WHERE trim(NAME)=trim(i.PAYMENT_TERM);
exception
when others then
l_flag:='E';
err_msg:=err_msg||'Termname Is Not Existing'||'/';
end;

-- conversion Type validation

BEGIN
SELECT CONVERSION_TYPE INTO l_convertion_type
from GL_DAILY_CONVERSION_TYPES
where CONVERSION_TYPE='User';
exception
when others then
l_flag:='E';
err_msg:=err_msg||'Conversion type Is Not Existing'||'/
';
end;

-- Inventory item validation


BEGIN
select distinct INVENTORY_ITEM_ID INTO L_INVENTORY_ITEM_ID
from MTL_SYSTEM_ITEMS where SEGMENT1=i.INVENTORY_ITEM;
exception
when others then
l_flag:='E';
err_msg:=err_msg||'Inventory item Is Not Existing'||'/'
;
end;

--To set-of-books id
begin
select SET_OF_BOOKS_ID into l_set_of_books_id
from AR_SYSTEM_PARAMETERS_ALL where ORG_ID=org_id;
exception
when others then
l_flag:='E';
err_msg:=err_msg||'set of books id Is Not Existing'||'/
';
end;

-- Tax code validation

BEGIN
SELECT TAX_RATE_CODE INTO L_tax_id
FROM zx_rates_b
WHERE trim(TAX_RATE_CODE)=trim(i.TAX_RATE_CODE);
exception
when others then
l_flag:='E';
err_msg:=err_msg||'Tax code Is Not Existing'||'/';
end;

-- Transction Type validation


BEGIN
select distinct CUST_TRX_TYPE_ID
INTO l_CUST_TRX_TYPE_ID
FROM RA_CUST_TRX_TYPES_all
WHERE NAME='Invoice';
EXCEPTION
WHEN OTHERS THEN
L_FLAG:='E';
ERR_MSG:=ERR_MSG||'Not Existing transaction type id for in
v'||'/';
END;

-- Batch source validation


BEGIN
SELECT DISTINCT BATCH_SOURCE_ID INTO L_batch_source_id
FROM RA_BATCH_SOURCES_ALL
WHERE trim(NAME)='MANUAL-OTHER';
exception
when others then
l_flag:='E';
err_msg:=err_msg||'Batch source name Is Not Existing'||
'/';
end;

-- Sequence Generation for Interface Line ID


select RA_CUSTOMER_TRX_LINES_S.NEXTVAL into l_sequence_no from dual;
l_attri2:='A'||l_sequence_no;

l_interface_line_attribute1:= l_sequence_no||i.INVOICE_NUMBER;
if l_flag<>'E' then
DBMS_OUTPUT.PUT_LINE('INSIDE LOOP');

INSERT INTO ra_interface_lines_all


(interface_line_id,
interface_line_context,
interface_line_attribute1 ,
interface_line_attribute2,
HEADER_ATTRIBUTE1,
batch_source_name,
--trx_number,
conversion_type,
conversion_rate,
set_of_books_id,
line_number,
line_type,
description,
currency_code,
cust_trx_type_id,
term_id,
orig_system_bill_customer_id,
orig_system_bill_address_id,
ORIG_SYSTEM_SHIP_CUSTOMER_ID,
ORIG_SYSTEM_SHIP_ADDRESS_ID,
ORIG_SYSTEM_SOLD_CUSTOMER_ID,
trx_date,
gl_date,
inventory_item_id,
quantity,
unit_selling_price,
amount,
uom_code,
created_by,
creation_date,
LAST_UPDATED_BY ,
last_update_date,
last_update_login,
org_id
)
VALUES
(l_sequence_no ,
'OPENINVOICE',
l_interface_line_attribute1,
'Open Invoice',
i.INVOICE_REFERENCE,
'MANUAL-OTHER',
-- 456,
'User',
L_CONVERSION_RATE,
l_set_of_books_id,
1,
'LINE',
I.DESCRIPTION,
L_CURRENCY_CODE ,
l_CUST_TRX_TYPE_ID,
l_term_id,
l_cust_account_id,
l_cust_bill_add_id,
l_cust_account_id,
l_cust_ship_add_id,
l_cust_account_id,
i.INVOICE_DATE,
i.GL_DATE,
L_INVENTORY_ITEM_ID,
i.QUANTITY,
i.UNIT_PRICE,
i.INVOICE_LINE_VALUE,
L_uom,
1110,
trunc(sysdate),
1110,
trunc(sysdate),
null,
org_id
);
INSERT INTO ra_interface_lines_all
(interface_line_id,
interface_line_context,
interface_line_attribute1 ,
interface_line_attribute2,
HEADER_ATTRIBUTE1,
batch_source_name,
--trx_number,
conversion_type,
conversion_rate,
set_of_books_id,
line_number,
line_type,
description,
currency_code,
cust_trx_type_id,
term_id,
orig_system_bill_customer_id,
orig_system_bill_address_id,
ORIG_SYSTEM_SHIP_CUSTOMER_ID,
ORIG_SYSTEM_SHIP_ADDRESS_ID,
ORIG_SYSTEM_SOLD_CUSTOMER_ID,
trx_date,
gl_date,
inventory_item_id,
quantity,
unit_selling_price,
amount,
uom_code,
created_by,
creation_date,
LAST_UPDATED_BY ,
last_update_date,
last_update_login,
org_id,
TAX_CODE
)
VALUES
(l_sequence_no ,
'OPENINVOICE',
l_interface_line_attribute1,
'Open Invoice',
i.INVOICE_REFERENCE,
'MANUAL-OTHER',
-- 456,
'User',
L_CONVERSION_RATE,
l_set_of_books_id,
1,
'TAX',
I.DESCRIPTION,
L_CURRENCY_CODE ,
l_CUST_TRX_TYPE_ID,
l_term_id,
l_cust_account_id,
l_cust_bill_add_id,
l_cust_account_id,
l_cust_ship_add_id,
l_cust_account_id,
i.INVOICE_DATE,
i.GL_DATE,
L_INVENTORY_ITEM_ID,
i.QUANTITY,
i.UNIT_PRICE,
i.INVOICE_LINE_VALUE,
L_uom,
1110,
trunc(sysdate),
1110,
trunc(sysdate),
null,
org_id,
L_tax_id
);

update XX_AR_INVOICE_STG set status_flag='P' where rowid=i.rowid;


commit;
else
DBMS_OUTPUT.PUT_LINE('ERROR LOOP');
update XX_AR_INVOICE_STG set status_flag='E',ERR_MESSEGE=err_msg where rowid=i.
rowid;
commit;
end if;
err_msg:='';
end loop;
exception
when others then
null;
fnd_file.put_line(FND_FILE.LOG, 'Error in mail loop -code: '||SQLCODE||' Error
message: '||SQLERRM);
end;
end XX_AR_INVOICE_IMP_PKG;
/

S-ar putea să vă placă și