Sei sulla pagina 1di 7

CREATE OR REPLACE PACKAGE APPS.

XX_RECEIPT_CREATE_PKG AS
PROCEDURE XX_RECEIPT_CREATE_PROC(ERRBUF OUT VARCHAR2,RETCODE OUT NUMBER);
END XX_RECEIPT_CREATE_PKG;
/

XX_RECEIPT_CREATE_PKG.XX_RECEIPT_CREATE_PROC
--==============================================================================
============
CREATE OR REPLACE PACKAGE BODY APPS.XX_RECEIPT_CREATE_PKG AS
PROCEDURE XX_RECEIPT_CREATE_PROC(ERRBUF OUT VARCHAR2,RETCODE OUT NUMBER) IS

p_api_version NUMBER;
p_init_msg_list VARCHAR2(240);
p_commit VARCHAR2(240);
p_validation_level NUMBER;
p_doc_sequence_value NUMBER;
p_issuer_name VARCHAR2(240);
p_issue_date DATE;
p_issuer_bank_branch_id NUMBER;
p_deposit_date DATE;
x_return_status VARCHAR2(1);
x_msg_count NUMBER;
x_msg_data VARCHAR2(240);
p_cr_id NUMBER;
p_global_attribute_rec AR_RECEIPT_API_PUB.global_attribute_rec_type;
p_attribute_rec AR_RECEIPT_API_PUB.attribute_rec_type;
p_customer_number VARCHAR2(240);
p_customer_site_use_id NUMBER;
p_customer_name VARCHAR2(240);
p_customer_id NUMBER;
p_customer_receipt_reference VARCHAR2(40);
p_receipt_date DATE;
p_amount NUMBER;
p_receipt_number VARCHAR2(240);
p_receipt_method_id NUMBER;
p_receipt_method_name varchar2(250);
p_currency_code VARCHAR2(10);
p_gl_date DATE; --:='28-FEB-2010';
qb_transaction_num NUMBER;
p_exchange_rate NUMBER;
p_exchange_rate_type VARCHAR2(240);
p_comments VARCHAR2(240);
l_error_flag varchar2(1):='N';
l_error_mesg varchar2(2000);
l_concat_error_mesg varchar2(4000);
l_rec_count number :=0;
l_rec_cnt_success number:=0;
l_rec_cnt_failed number:=0;

-- VARIABLES TO CAPTURE VALIDATIONS


L_CUST_ID NUMBER;
L_CUST_SITE NUMBER;
L_CURRENCY_CODE VARCHAR2(3);
L_PERIOD_STATUS VARCHAR2(10);
L_RECEIPT_METHOD_ID NUMBER;
L_METHOD_CODE VARCHAR2(60);
L_PERIOD VARCHAR2(10);
l_CUST_ACCT_SITE_ID number;
L_cust_number number;

cursor c1 is
select *
from XX_RECEIPTS_STG
where STATUS_CODE='N';
BEGIN
FOR C_REC IN C1 LOOP
L_ERROR_FLAG :='N';
L_ERROR_MESG := NULL;
L_CONCAT_ERROR_MESG := NULL;
L_CUST_ID := NULL;
L_CUST_SITE := NULL;
L_CURRENCY_CODE := NULL;
L_PERIOD_STATUS := NULL;
L_RECEIPT_METHOD_ID := NULL;
L_METHOD_CODE := NULL;
l_rec_count:=l_rec_count+1;

--- to get cutomer id

BEGIN
MO_GLOBAL.INIT('AR');
SELECT CUSTOMER_ID,CUSTOMER_NUMBER INTO L_CUST_ID,L_cust_num
ber
FROM AR_customers
WHERE upper(TRIM(substr(CUSTOMER_NAME,1,6)))=upper(TRIM(su
bstr(C_REC.CUSTOMER_NAME,1,6)));
fnd_file.put_line(fnd_file.log,'CUSTOMER-NUMBER: '||L_cust_
number);
exception
WHEN NO_DATA_FOUND
THEN
l_error_mesg:='customer Is Not Existing'||'/';
l_concat_error_mesg:=l_concat_error_mesg ||l_error_mesg
;
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_error_flag:='Y';
WHEN OTHERS
THEN
l_error_mesg:= SUBSTR(SQLERRM,1,255);
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_concat_error_mesg:=l_concat_error_mesg||'~'||l_error_mesg;
l_error_flag:='Y';
end;
-- to get bill to address id

begin
SELECT HCSUA.SITE_USE_ID
INTO L_CUST_SITE
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_cust_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.STATUS='A' and rownum=1;
fnd_file.put_line(fnd_file.log,'BILL TO: '||L_CUST_SITE );
exception
WHEN NO_DATA_FOUND
THEN
l_error_mesg:=l_error_mesg||'Cust Account Site id BILL_TO Is Not Exi
sting'||'/';
l_concat_error_mesg:=l_concat_error_mesg ||l_error_mesg;
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_error_flag:='Y';
WHEN OTHERS
THEN
l_error_mesg:= SUBSTR(SQLERRM,1,255);
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_concat_error_mesg:=l_concat_error_mesg||'~'||l_error_mesg;
l_error_flag:='Y';
end;
DBMS_OUTPUT.PUT_LINE('BILL TO ADDRESS ID'||L_CUST_SITE);

-- =====================================================
-- CURRENCY VALIDATION STARTS --
-- =====================================================
FND_FILE.PUT_LINE ( fnd_file.LOG,'Currency Validation - Starts ');
BEGIN
SELECT CURRENCY_CODE
INTO L_CURRENCY_CODE
FROM FND_CURRENCIES
WHERE UPPER(CURRENCY_CODE)=UPPER(TRIM(C_REC.CURRENCY_CODE))
AND ENABLED_FLAG='Y';
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_mesg:='Currency not Defined in EBS';
l_concat_error_mesg:=l_concat_error_mesg ||l_error_mesg;
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_error_flag:='Y';
WHEN OTHERS
THEN
l_error_mesg:= SUBSTR(SQLERRM,1,255);
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_concat_error_mesg:=l_concat_error_mesg||'~'||l_error_mesg;
l_error_flag:='Y';
END;
dbms_output.put_line('Currency is '||L_CURRENCY_CODE);
FND_FILE.PUT_LINE ( fnd_file.LOG,'Currency is '||L_CURRENCY_CODE);
FND_FILE.PUT_LINE ( fnd_file.LOG,'Currency Validation - Ends ');
-- =====================================================
-- CURRENCY VALIDATION ENDS --
-- =====================================================
-- ====================================================
-- FETCHIING RECEIPT METHOD ID STARTS
-- ====================================================
FND_FILE.PUT_LINE ( fnd_file.LOG,'Fetching Receipt Method ID Starts ');

BEGIN
SELECT ARM.RECEIPT_METHOD_ID
INTO L_RECEIPT_METHOD_ID
FROM AR_RECEIPT_METHODS ARM
WHERE UPPER(TRIM(ARM.NAME))=UPPER(TRIM(C_REC.PAYMENT_METHOD_NAME))
AND ARM.END_DATE IS NULL;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_mesg:='RECEIPT METHOD IS NOT DEFINED IN EBS';
l_concat_error_mesg:=l_concat_error_mesg ||l_error_mesg;
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_error_flag:='Y';
WHEN OTHERS
THEN
l_error_mesg:= SUBSTR(SQLERRM,1,255);
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_concat_error_mesg:=l_concat_error_mesg||'~'||l_error_mesg;
l_error_flag:='Y';

END;
FND_FILE.PUT_LINE ( fnd_file.LOG,'RECEIPT Method Validation - Ends '||'METHO
D ID IS '||L_RECEIPT_METHOD_ID||' For Method '||L_METHOD_CODE);
-- ====================================================
-- FETCHIING RECEIPT METHOD ID ENDS
-- ====================================================
FND_FILE.PUT_LINE ( fnd_file.LOG,'ASSIGNING VALUES TO API VARIABLES ');
BEGIN
IF l_error_flag ='N' THEN
p_amount := c_rec.RECEIPT_AMOUNT;
p_receipt_number := c_rec.RECEIPT_NUMBER;
p_receipt_method_id := l_receipt_method_id;
p_receipt_method_name := c_rec.PAYMENT_METHOD_NAME;
p_customer_id := l_cust_id;
p_customer_number := c_rec.CUSTOMER_NUMBER;
--p_customer_name := c_rec.CUSTOMER_NAME;
p_currency_code := l_currency_code;
p_receipt_date := c_rec.receipt_date;
p_gl_date := '31-OCT-2010';
p_customer_site_use_id := l_cust_site;
p_customer_receipt_reference := c_rec.RECEIPT_NUMBER;
--p_exchange_rate :=c_rec.EXCHANGE_RATE;
--p_exchange_rate_type :=c_rec.EXCHANGE_RATE_TYPE;
p_receipt_date :=c_rec.RECEIPT_DATE;
--p_comments :=c_rec.COMMENTS;
FND_FILE.PUT_LINE ( fnd_file.LOG,'STARTING API');
AR_RECEIPT_API_PUB.Create_cash (
p_api_version => 1.0
,p_init_msg_list => FND_API.G_TRUE
,p_commit => FND_API.G_TRUE
,p_currency_code => p_currency_code
,p_amount => p_amount
,p_receipt_number => p_receipt_number
,p_receipt_date => p_receipt_date
,p_gl_date => p_gl_date
,p_customer_id => p_customer_id
-- ,p_customer_number => p_customer_number
,p_customer_site_use_id => p_customer_site_use_id
,p_receipt_method_id => l_receipt_method_id
-- ,p_receipt_method_name => p_receipt_method_name
,p_exchange_rate => p_exchange_rate
,p_exchange_rate_type => p_exchange_rate_type
-- ,p_comments => p_comments
-- ,p_doc_sequence_value => NULL;
,p_customer_receipt_reference => p_customer_receipt_reference
,x_return_status => x_return_status
,x_msg_count => x_msg_count
,x_msg_data => x_msg_data
,p_cr_id => p_cr_id

);

FND_FILE.PUT_LINE ( fnd_file.LOG,'API ENDS ');


IF (x_return_status = 'S') THEN
COMMIT;
l_rec_cnt_success:=l_rec_cnt_success+1;
FND_FILE.PUT_LINE ( fnd_file.LOG,'API SUCCESSFULLY COMPLETED ');
FND_FILE.PUT_LINE ( fnd_file.LOG,'Return Status = '|| SUBSTR (x_return_statu
s,1,255));
FND_FILE.PUT_LINE ( fnd_file.LOG,'Message Data = '|| x_msg_data);
FND_FILE.PUT_LINE ( fnd_file.LOG,'CASH RECEIPT ID IS '||P_CR_ID);
FND_FILE.PUT_LINE ( fnd_file.LOG,'==========================================
==============');
FND_FILE.PUT_LINE ( fnd_file.LOG,'
');
FND_FILE.PUT_LINE ( fnd_file.LOG,'==========================================
==============');

UPDATE XX_RECEIPTS_STG
SET STATUS_CODE='R'
WHERE RECEIPT_NUMBER=C_REC.RECEIPT_NUMBER;
dbms_output.put_line('SUCCESS');
dbms_output.put_line('Return Status = '|| SUBSTR (x_return_sta
tus,1,255));
dbms_output.put_line('Message Count = '|| x_msg_count);
dbms_output.put_line('Message Data = '|| x_msg_data);
dbms_output.put_line('p_cr_id = '|| p_cr_id);
ELSE
--ROLLBACK;
l_rec_cnt_failed:=l_rec_cnt_failed+1;
FND_FILE.PUT_LINE ( fnd_file.LOG,'API FAILED ');
FND_FILE.PUT_LINE ( fnd_file.LOG,'Return Status = '|| SUBSTR (x_r
eturn_status,1,255));
FND_FILE.PUT_LINE ( fnd_file.LOG,'Message Data = '|| x_msg_data);
dbms_output.put_line('x_return_status');

-- UPDATING STAGING TABLES


UPDATE XX_RECEIPTS_STG
SET STATUS_CODE='E' --CREATE_ERROR_MESG = X_MSG_DATA --'API FAILED '||' '
||'With Following Error '||' '||x_msg_data)
WHERE RECEIPT_NUMBER=C_REC.RECEIPT_NUMBER;
dbms_output.put_line('Return Status = '|| SUBSTR (x_return_status,1,255));
dbms_output.put_line('Message Count = '|| TO_CHAR(x_msg_count ));
dbms_output.put_line('Message Data = '|| SUBSTR (x_msg_data,1,255));
dbms_output.put_line(APPS.FND_MSG_PUB.Get ( p_msg_index => APPS.FND_MSG_PUB.G
_LAST,p_encoded=> APPS.FND_API.G_FALSE));
IF x_msg_count >=0 THEN
FOR I IN 1..10 LOOP
dbms_output.put_line(I||'. '|| SUBSTR (FND_MSG_PUB.Get(p_encoded
=> FND_API.G_FALSE ), 1, 255));
FND_FILE.PUT_LINE ( fnd_file.LOG,SUBSTR (FND_MSG_PUB.Get(p_encoded
=> FND_API.G_FALSE ), 1, 255));
END LOOP;
END IF;
END IF;
ELSE
FND_FILE.PUT_LINE ( fnd_file.LOG,'ERROR FLAG IS '||l_error_flag ||' '|| l_conca
t_error_mesg);
UPDATE XX_RECEIPTS_STG
SET STATUS_CODE='E'--,CREATE_ERROR_MESG =L_CONCAT_ERROR_MESG,RECEIPT_CREA
TED='N' --'API FAILED '||' '||'With Following Error '||' '||x_msg_data)
WHERE RECEIPT_NUMBER=C_REC.RECEIPT_NUMBER;
END IF;
END;
END LOOP;
dbms_output.put_line('Total Record Count Is '||l_rec_count);
FND_FILE.PUT_LINE(FND_FILE.LOG,' No of Records Read '||l_rec
_count);
FND_FILE.PUT_LINE(FND_FILE.LOG,' No of Records Successfully Completed '||l_rec
_cnt_success);
FND_FILE.PUT_LINE(FND_FILE.LOG, 'No of Records Errored Out '||l_rec
_cnt_failed);
END XX_RECEIPT_CREATE_PROC;
END XX_RECEIPT_CREATE_PKG;
/