You are on page 1of 27

CREATE OR REPLACE PACKAGE BODY prxl_ar_inv_conv_pkg

AS
/*********************************************************************************
||
|| Name : PRXL_AR_INV_GENERATE_REPORT
||
|| Description : Procedure used to write Messages in Output File
||
|| Ver Date Author Modification
||
|| 1.0 15-APR-09 Narasimha Rao Akula Initial Version
||
*********************************************************************************/
PROCEDURE prxl_ar_inv_generate_report (
p_tot_records_lines IN VARCHAR2,
p_tot_records_dist IN VARCHAR2
)
AS
l_str VARCHAR2 (1000) := '*************************';
l_tot_rec_mig NUMBER;
l_val_rec_lines NUMBER;
l_inval_rec_lines NUMBER;
l_val_rec_dist NUMBER;
l_inval_rec_dist NUMBER;
BEGIN
IF g_conv_opt = 'VALIDATE'
THEN
SELECT COUNT (1)
INTO l_tot_rec_mig
FROM prxl_ar_inv_conv_mig;

SELECT COUNT (1)


INTO l_val_rec_lines
FROM prxl_ar_inv_lines_conv_stg
WHERE error_code = 'VALID';

SELECT COUNT (1)


INTO l_inval_rec_lines
FROM prxl_ar_inv_lines_conv_stg
WHERE error_code = 'INVALID';

SELECT COUNT (1)


INTO l_val_rec_dist
FROM prxl_ar_inv_dist_conv_stg
WHERE error_code = 'VALID';

SELECT COUNT (1)


INTO l_inval_rec_dist
FROM prxl_ar_inv_dist_conv_stg
WHERE error_code = 'INVALID';

prxl_common_pkg.write_output (' ');


prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output
( l_str
|| ' Validation Report For prxl_ar_inv_lines_conv_stg '
|| l_str
);
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output ( 'Number of Records in Migration Table ::'
|| l_tot_rec_mig
);
prxl_common_pkg.write_output ( 'Number of Records in Staging Table ::'
|| p_tot_records_lines
);
prxl_common_pkg.write_output ( 'Number of Valid Records ::'
|| l_val_rec_lines
);
prxl_common_pkg.write_output ( 'Number of InValid Records ::'
|| l_inval_rec_lines
);
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output
( l_str
|| ' Validation Report For prxl_ar_inv_dist_conv_stg '
|| l_str
);
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output ( 'Number of Records in Staging Table ::'
|| p_tot_records_dist
);
prxl_common_pkg.write_output ('Number of Valid Records ::'
|| l_val_rec_dist
);
prxl_common_pkg.write_output ( 'Number of InValid Records ::'
|| l_inval_rec_dist
);
prxl_common_pkg.write_output (' ');
ELSIF g_conv_opt = 'PROCESS'
THEN
SELECT COUNT (1)
INTO l_tot_rec_mig
FROM prxl_ar_inv_conv_mig;

SELECT COUNT (1)


INTO l_val_rec_lines
FROM prxl_ar_inv_lines_conv_stg
WHERE error_code = 'PROCESSED';

SELECT COUNT (1)


INTO l_inval_rec_lines
FROM prxl_ar_inv_lines_conv_stg
WHERE error_code = 'UNPROCESSED';

SELECT COUNT (1)


INTO l_val_rec_dist
FROM prxl_ar_inv_dist_conv_stg
WHERE error_code = 'PROCESSED';

SELECT COUNT (1)


INTO l_inval_rec_dist
FROM prxl_ar_inv_dist_conv_stg
WHERE error_code = 'UNPROCESSED';

prxl_common_pkg.write_output (' ');


prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output
( l_str
|| ' Process Report For prxl_ar_inv_lines_conv_stg '
|| l_str
);
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output ( 'Number of Records in Migration Table ::'
|| l_tot_rec_mig
);
prxl_common_pkg.write_output
( 'Number of Valid Records in Staging Table ::'
|| p_tot_records_lines
);
prxl_common_pkg.write_output ( 'Number of Processed Records ::'
|| l_val_rec_lines
);
prxl_common_pkg.write_output ( 'Number of UnProcessed Records ::'
|| l_inval_rec_lines
);
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output
( l_str
|| ' Process Report For prxl_ar_inv_dist_conv_stg '
|| l_str
);
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output
( 'Number of Valid Records in Staging Table ::'
|| p_tot_records_dist
);
prxl_common_pkg.write_output ( 'Number of Processed Records ::'
|| l_val_rec_dist
);
prxl_common_pkg.write_output ( 'Number of UnProcessed Records ::'
|| l_inval_rec_dist
);
prxl_common_pkg.write_output (' ');
ELSE
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output (l_str || '***Load Report***' || l_str);
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output
('11i AR Invoice Lines Data has been copied from Migratin Table to Lines
Staging Table'
);
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output
( 'Number of Records copied into Lines Staging Table are ::'
|| p_tot_records_lines
);
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output
('AR Invoice Distributions Data has been copied from Migratin Table to
Distributions Staging Table'
);
prxl_common_pkg.write_output (' ');
prxl_common_pkg.write_output
( 'Number of Records copied into Staging Table are ::'
|| p_tot_records_dist
);
prxl_common_pkg.write_output (' ');
END IF;
END prxl_ar_inv_generate_report;

/
***********************************************************************************
*******************
||
|| Name : PRXL_AR_INV_CONV_LOAD_PROC
||
|| Description : Procedure used to Load the Data from Migration Schema to
Staging Table
||
|| Ver Date Author Modification
||
|| 1.0 15-APR-09 Narasimha Rao Akula Initial Version
||
***********************************************************************************
**********************/
PROCEDURE prxl_ar_inv_conv_load_proc
AS
BEGIN
BEGIN
INSERT INTO prxl_ar_inv_lines_conv_stg
(batch_source_name,
operating_unit,
trx_number,
trx_date,
line_number,
line_type,
line_description,
line_amount,
bill_to_customer_number,
location,
currency_code,
transaction_type,
conversion_type,
conversion_rate,
conversion_date,
term_name,
gl_date,
autotax,
tax_rate,
tax_code,
attribute2,
attribute3,
attribute4,
attribute9,
attribute12,
attribute13,
attribute14,
error_code
)
(SELECT DISTINCT batch_source_name,
UPPER (operating_unit),
trx_number,
trx_date,
line_number,
line_type,
NVL (line_description,
'Description For Invoice Number - '
)
|| trx_number,
line_amount,
customer_number,
location,
invoice_currency_code,
UPPER (transaction_type),
'User',
NVL (conversion_rate, 1),
conversion_date,
UPPER (term_name),
gl_date,
autotax,
tax_rate,
tax_code,
attribute2,
attribute3,
attribute4,
attribute9,
attribute12,
attribute13,
attribute14,
'NEW'
FROM prxl_ar_inv_conv_mig);

-- Call Procedure for Output file Message


prxl_ar_inv_generate_report (p_tot_records_lines => SQL%ROWCOUNT,
p_tot_records_dist => NULL
);
EXCEPTION
WHEN OTHERS
THEN
prxl_common_pkg.write_log
( 'Error occured while upload the data into staging lines table : SQLCODE is
'
|| SQLCODE
|| 'SQLMSG is '
|| SQLERRM
);
END;

BEGIN
INSERT INTO prxl_ar_inv_dist_conv_stg
(batch_source_name,
operating_unit,
trx_number,
line_number,
account_class,
dist_amount,
gl_date,
segment1,
segment2,
segment3,
segment4,
segment5,
segment6,
segment7,
segment8,
segment9,
error_code
)
(SELECT batch_source_name,
UPPER (operating_unit),
trx_number,
line_number,
account_class,
line_amount,
gl_date,
segment1,
segment2,
segment3,
segment4,
segment5,
segment6,
segment7,
segment8,
segment9,
'NEW'
FROM prxl_ar_inv_conv_mig);

-- Procedure call for Output file Message


prxl_ar_inv_generate_report (p_tot_records_lines => NULL,
p_tot_records_dist => SQL%ROWCOUNT
);
EXCEPTION
WHEN OTHERS
THEN
prxl_common_pkg.write_log
( 'Error occured while upload the data into staging dist table :SQLCODE is
'
|| SQLCODE
|| 'SQLMSG is '
|| SQLERRM
);
END;
END prxl_ar_inv_conv_load_proc;

/
***********************************************************************************
************************
||
|| Name : PRXL_AR_INV_CONV_VALID_PROC
||
|| Type : Procedure
||
|| Description : Procedure Used to Validate the AR Open Invoices Data and
updates Staging table
||
|| Ver Date Author Modification
||
|| 1.0 15-APR-09 Narasimha Rao Akula Initial Version
||
***********************************************************************************
**************************/
PROCEDURE prxl_ar_inv_conv_valid_proc
AS
l_org_id NUMBER;
l_set_of_bks_id NUMBER := fnd_profile.VALUE ('GL_SET_OF_BKS_ID');
l_fun_curr VARCHAR2 (10);
l_error_hmsg VARCHAR2 (1000);
l_error_lmsg VARCHAR2 (1000);
l_batch_source_name ra_batch_sources_all.NAME%TYPE;
l_data_count NUMBER := 0;
l_currency fnd_currencies.currency_code%TYPE;
l_cust_trx_type_id NUMBER;
l_term_id NUMBER;
l_cust_account_id NUMBER;
l_cust_site_id NUMBER;
l_location VARCHAR2 (40);
l_segment1 VARCHAR2 (25);
l_segment2 VARCHAR2 (25);
l_segment3 VARCHAR2 (25);
l_segment4 VARCHAR2 (25);
l_segment5 VARCHAR2 (25);
l_segment6 VARCHAR2 (25);
l_segment7 VARCHAR2 (25);
l_segment8 VARCHAR2 (25);
l_segment9 VARCHAR2 (25);
l_code_combination_id NUMBER;
l_tot_records_lines NUMBER;
l_tot_records_dist NUMBER;
l_new_operating_unit VARCHAR2 (120); --- Added for MOCK 2
l_new_batch_source_name VARCHAR2 (120); --- Added for MOCK 2
l_new_transaction_type VARCHAR2 (120); --- Added for MOCK 2

CURSOR c_head
IS
SELECT ROWID,
operating_unit,
batch_source_name,
currency_code,
trx_number,
trx_date,
transaction_type,
term_name,
bill_to_customer_number,
location,
line_amount,
gl_date,
conversion_type,
conversion_rate,
line_number,
attribute2,
attribute3,
attribute4,
attribute9,
attribute12,
attribute13,
attribute14
FROM prxl_ar_inv_lines_conv_stg
WHERE error_code in( 'NEW','INVALID')
AND ROWNUM <= g_batch_size
ORDER BY trx_number, line_number;
CURSOR c_line (cp_trx_number VARCHAR2, cp_line_number NUMBER)
IS
SELECT ROWID,
operating_unit,
batch_source_name,
trx_number,
line_number,
account_class,
dist_amount,
segment1 co,
segment2 loc,
segment3 cc,
segment4 division,
segment5 client,
segment6 product,
segment7 na,
segment8 ic,
segment9 spare,
gl_date
FROM prxl_ar_inv_dist_conv_stg
WHERE error_code in( 'NEW','INVALID')
AND trx_number = cp_trx_number
AND line_number = cp_line_number
ORDER BY trx_number, line_number;
BEGIN
--To get the Total Count of Records in the Lines Stag table going to be Validated
SELECT COUNT (1)
INTO l_tot_records_lines
FROM prxl_ar_inv_lines_conv_stg
WHERE error_code = 'NEW';

--To get the Total Count of Records in the Distribution Stag table going to be
Validated
SELECT COUNT (1)
INTO l_tot_records_dist
FROM prxl_ar_inv_dist_conv_stg
WHERE error_code = 'NEW';

BEGIN
SELECT currency_code
INTO l_fun_curr
FROM gl_ledgers
WHERE ledger_id = l_set_of_bks_id;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
prxl_common_pkg.write_log
('No data found when deriving functional currency;');
WHEN TOO_MANY_ROWS
THEN
prxl_common_pkg.write_log
('Multiple rows found when deriving functional currency code;');
WHEN OTHERS
THEN
--l_fun_curr:=NULL;
prxl_common_pkg.write_log
( 'Unexpected error when deriving functional currency code. Error code:'
|| SQLCODE
|| 'Error Msg:'
|| SQLERRM
|| ';'
);
END;

FOR cv_valid_rec_head IN c_head


LOOP
l_error_hmsg := NULL;
l_term_id := NULL;
l_cust_trx_type_id := NULL;
l_cust_account_id := NULL;
l_cust_site_id := NULL;
l_location := NULL;
l_org_id := NULL;
l_new_operating_unit := NULL; -- Added for MOCK 2
l_new_batch_source_name := NULL; -- Added for MOCK 2
l_new_transaction_type := NULL; -- Added for MOCK 2

IF cv_valid_rec_head.operating_unit IS NULL
THEN
l_error_hmsg := l_error_hmsg || 'Operating unit is null;';
ELSE
BEGIN
SELECT new_op_unit
INTO l_new_operating_unit
FROM pxl_op_unit_xln
WHERE UPPER (old_op_unit) =
UPPER (cv_valid_rec_head.operating_unit);
-- Added for MOCK 2
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_hmsg :=
l_error_hmsg || 'No data found when deriving mapping operating unit;';
WHEN TOO_MANY_ROWS
THEN
l_error_hmsg :=
l_error_hmsg
|| 'Multiple rows found when deriving mapping operating unit;';
WHEN OTHERS
THEN
l_error_hmsg :=
l_error_hmsg
|| 'Unexpected error when deriving mapping operating unit. Error code:'
|| SQLCODE
|| 'Error Msg:'
|| SQLERRM
|| ';';
END;

BEGIN
SELECT organization_id
INTO l_org_id
FROM hr_operating_units
WHERE UPPER (NAME) = upper(l_new_operating_unit);
-- cv_valid_rec_head.operating_unit; --- Added for MOCK 2
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_hmsg := l_error_hmsg || 'No data found when deriving org id;';
WHEN TOO_MANY_ROWS
THEN
l_error_hmsg :=
l_error_hmsg || 'Multiple rows found when deriving org id;';
WHEN OTHERS
THEN
l_error_hmsg :=
l_error_hmsg
|| 'Unexpected error when deriving org id. Error code:'
|| SQLCODE
|| 'Error Msg:'
|| SQLERRM
|| ';';
END;
END IF;

IF cv_valid_rec_head.batch_source_name IS NULL
THEN
l_error_hmsg := l_error_hmsg || 'Batch source name is null;';
ELSE
l_batch_source_name := NULL;

BEGIN
SELECT new_batch_source_name
INTO l_new_batch_source_name
FROM prxl_batch_source_name_mapping
WHERE UPPER (old_batch_source_name) =
cv_valid_rec_head.batch_source_name;
--- Added for MOCK 2
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_hmsg :=
l_error_hmsg
|| 'No data found when deriving mapping batch source name;';
WHEN TOO_MANY_ROWS
THEN
l_batch_source_name := NULL;
l_error_hmsg :=
l_error_hmsg
|| 'Multiple rows found when deriving mapping batch source name;';
WHEN OTHERS
THEN
l_error_hmsg :=
l_error_hmsg
|| 'Unexpected error when deriving mapping batch source name. Error code:'
|| SQLCODE
|| 'Error Msg:'
|| SQLERRM
|| ';';
END;

BEGIN
SELECT NAME
INTO l_batch_source_name
FROM ra_batch_sources_all
WHERE NAME = l_new_batch_source_name
--cv_valid_rec_head.batch_source_name --- Added for MOCK 2
AND org_id = l_org_id
AND status = 'A'
AND SYSDATE BETWEEN NVL (start_date, SYSDATE) AND NVL (end_date,
SYSDATE
);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_hmsg :=
l_error_hmsg || 'No data found when deriving batch source name;';
WHEN TOO_MANY_ROWS
THEN
l_batch_source_name := NULL;
l_error_hmsg :=
l_error_hmsg || 'Multiple rows found when deriving batch source name;';
WHEN OTHERS
THEN
l_error_hmsg :=
l_error_hmsg
|| 'Unexpected error when deriving batch source name. Error code:'
|| SQLCODE
|| 'Error Msg:'
|| SQLERRM
|| ';';
END;
END IF;

IF cv_valid_rec_head.trx_date IS NULL
THEN
l_error_hmsg := l_error_hmsg || 'Transaction date is null;';
END IF;

IF cv_valid_rec_head.line_amount IS NULL
THEN
l_error_hmsg := l_error_hmsg || 'Invoice amount is null;';
END IF;

-----------------------------
-- Currency Validation
-----------------------------
IF cv_valid_rec_head.currency_code IS NULL
THEN
l_error_hmsg := l_error_hmsg || 'Currency code is null;';
ELSE
BEGIN
SELECT currency_code
INTO l_currency
FROM fnd_currencies
WHERE UPPER (currency_code) =
TRIM (UPPER (cv_valid_rec_head.currency_code))
AND enabled_flag = 'Y';

IF UPPER (TRIM (l_currency)) <> UPPER (TRIM (l_fun_curr))


AND cv_valid_rec_head.conversion_rate IS NULL
THEN
l_error_hmsg :=
l_error_hmsg
|| 'Exchange Rate is null Or Functional Currency is different from
Transactional Currency;';
END IF;
EXCEPTION
WHEN OTHERS
THEN
l_error_hmsg := l_error_hmsg || 'Currency is not defined or disabled;';
END;
END IF;

-------------------------------
-- Transaction Type Validation
-------------------------------
IF cv_valid_rec_head.transaction_type IS NULL
THEN
l_error_hmsg := l_error_hmsg || 'Transaction type is null;';
ELSE
BEGIN
SELECT new_transaction_type
INTO l_new_transaction_type
FROM prxl_transaction_type_mapping
WHERE UPPER (old_transaction_type) = cv_valid_rec_head.transaction_type;
--- Added for MOCK 2
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_hmsg :=
l_error_hmsg
|| 'No data found when deriving mapping transaction type id;';
WHEN TOO_MANY_ROWS
THEN
l_error_hmsg :=
l_error_hmsg
|| 'Multiple rows found when deriving mapping transaction type id;';
WHEN OTHERS
THEN
l_error_hmsg :=
l_error_hmsg
|| 'Unexpected error when deriving mapping transaction type id. Error code:'
|| SQLCODE
|| 'Error Msg:'
|| SQLERRM
|| ';';
END;

BEGIN
l_cust_trx_type_id := NULL;

SELECT cust_trx_type_id
INTO l_cust_trx_type_id
FROM ra_cust_trx_types_all
WHERE UPPER (NAME) =UPPER(l_new_transaction_type)
--TRIM (cv_valid_rec_head.transaction_type)
AND org_id = l_org_id;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_hmsg :=
l_error_hmsg || 'No data found when deriving transaction type id;';
WHEN TOO_MANY_ROWS
THEN
l_error_hmsg :=
l_error_hmsg
|| 'Multiple rows found when deriving transaction type id;';
WHEN OTHERS
THEN
l_error_hmsg :=
l_error_hmsg
|| 'Unexpected error when deriving transaction type id. Error code:'
|| SQLCODE
|| 'Error Msg:'
|| SQLERRM
|| ';';
END;
END IF;

-------------------------------
-- Derivation of Term_id
-------------------------------
IF cv_valid_rec_head.term_name IS NOT NULL
THEN
l_term_id := NULL;

BEGIN
SELECT term_id
INTO l_term_id
FROM ra_terms
WHERE UPPER (NAME) = TRIM (cv_valid_rec_head.term_name)
AND SYSDATE BETWEEN NVL (start_date_active, SYSDATE)
AND NVL (end_date_active, SYSDATE);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_hmsg :=
l_error_hmsg || 'No data found when deriving payment terms;';
WHEN TOO_MANY_ROWS
THEN
l_term_id := NULL;
l_error_hmsg :=
l_error_hmsg || 'Multiple rows found when deriving payment terms;';
WHEN OTHERS
THEN
l_term_id := NULL;
l_error_hmsg :=
l_error_hmsg
|| 'Unexpected error when deriving payment term.Error code:'
|| SQLCODE
|| 'Error Msg:'
|| SQLERRM
|| ';';
END;
END IF;

---------------------------------------------------
-- Derivation of Cust_Account_Id,Cust_Acct_Site_Id
----------------------------------------------------
IF cv_valid_rec_head.bill_to_customer_number IS NULL
THEN
l_error_hmsg := l_error_hmsg || ' Customer number is null ;';
ELSIF cv_valid_rec_head.bill_to_customer_number IS NOT NULL
THEN
BEGIN
l_cust_account_id := NULL;
l_cust_site_id := NULL;

SELECT UNIQUE hca.cust_account_id,


hcas.cust_acct_site_id,
hcsu.location
INTO l_cust_account_id,
l_cust_site_id,
l_location
FROM hz_cust_accounts_all hca,
hz_cust_acct_sites_all hcas,
hz_party_sites hps,
hz_cust_site_uses_all hcsu
WHERE hca.account_number =
cv_valid_rec_head.bill_to_customer_number
AND hcsu.location = cv_valid_rec_head.location
AND hca.cust_account_id = hcas.cust_account_id
AND hcas.org_id = l_org_id
AND hcas.org_id = hcsu.org_id
AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id(+)
AND hcas.party_site_id = hps.party_site_id
AND hcsu.site_use_code = 'BILL_TO'
-- AND hcas.bill_to_flag = 'P' COMMENTED FOR MOCK
1
AND hcas.status = 'A'
AND hps.status = 'A'
AND hca.status = 'A'
AND hcsu.status = 'A';
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_hmsg :=
l_error_hmsg || 'No data found when deriving customer number or site;';
WHEN TOO_MANY_ROWS
THEN
l_error_hmsg :=
l_error_hmsg
|| 'Multiple rows found when deriving customer number or site;';
WHEN OTHERS
THEN
l_error_hmsg :=
l_error_hmsg
|| 'Unexpected error when deriving customer number or site. Error code:'
|| SQLCODE
|| 'Error Msg:'
|| SQLERRM
|| ';';
END;
END IF;

--------------------------------------
--- Distribution Data Validation
--------------------------------------

FOR cv_valid_rec_lines IN c_line (cv_valid_rec_head.trx_number,


cv_valid_rec_head.line_number
)
LOOP
l_error_lmsg := NULL;
l_data_count := NULL;
l_code_combination_id := NULL;

IF cv_valid_rec_lines.dist_amount IS NULL
THEN
l_error_lmsg := 'Invoice account dist amount is null;';
END IF;

/*
-------------------------------
-- Operating Unit Validation
-------------------------------
IF cv_valid_rec_lines.operating_unit IS NULL
THEN
l_error_lmsg := l_error_lmsg || 'Operating unit is null;';

ELSE

BEGIN
SELECT organization_id
INTO l_org_id
FROM hr_operating_units
WHERE UPPER(name) = cv_valid_rec_lines.operating_unit;

EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_lmsg :=
l_error_lmsg ||'No data found when deriving org id;';
WHEN TOO_MANY_ROWS
THEN
l_error_lmsg :=
l_error_lmsg ||'Multiple rows found when deriving org id;';
WHEN OTHERS
THEN
l_error_lmsg :=
l_error_lmsg || 'Unexpected error when deriving org id. Error
code:'
|| SQLCODE
|| 'Error Msg:'
|| SQLERRM
|| ';'
;
END;

END IF;

-------------------------------
-- Batch Source Name Validation
-------------------------------
IF cv_valid_rec_lines.batch_source_name IS NULL
THEN
l_error_lmsg := l_error_hmsg|| 'Batch source name is null;';
ELSE
l_batch_source_name := NULL;

BEGIN
SELECT name
INTO l_batch_source_name
FROM ra_batch_sources_all
WHERE name = cv_valid_rec_lines.batch_source_name
AND org_id = l_org_id
AND status = 'A'
AND SYSDATE BETWEEN NVL (start_date, SYSDATE) AND NVL (end_date,
SYSDATE
);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_lmsg :=
l_error_lmsg || 'No data found when deriving batch source name;';
WHEN TOO_MANY_ROWS
THEN
l_batch_source_name := NULL;
l_error_lmsg :=
l_error_lmsg
|| 'Multiple rows found when deriving batch source name;';
WHEN OTHERS
THEN
l_error_lmsg :=
l_error_lmsg
|| 'Unexpected error when deriving batch source name. Error code:'
|| SQLCODE
|| 'Error Msg:'
|| SQLERRM
|| ';';
END;
END IF;

*/
-------------------------------
-- GL Period Validation
-------------------------------
/*--Commented by chaitanya as per the suresh comments

IF cv_valid_rec_lines.gl_date IS NULL
THEN
l_error_lmsg := l_error_lmsg || 'GL date is null;';
ELSE
BEGIN
l_data_count := NULL;

SELECT COUNT (1)


INTO l_data_count
FROM gl_period_statuses gps
WHERE gps.closing_status = 'O'
AND gps.set_of_books_id = l_set_of_bks_id
AND TO_DATE (cv_valid_rec_lines.gl_date, 'DD/MM/RRRR')
BETWEEN gps.start_date
AND gps.end_date;
IF l_data_count = 0
THEN
l_error_lmsg := l_error_lmsg || 'GL date is not in AR open period;';
END IF;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_lmsg :=
l_error_lmsg || 'No data found when deriving GL period status in AR;';
WHEN TOO_MANY_ROWS
THEN
l_error_lmsg :=
l_error_lmsg
|| 'Multiple rows found when deriving GL period status in AR;';
WHEN OTHERS
THEN
l_error_lmsg :=
l_error_lmsg
|| 'Unexpected error when deriving GL period status in AR. Error code:'
|| SQLCODE
|| 'Error Msg:'
|| SQLERRM
|| ';';
END;
END IF;
*/
----------------------------------------------
-- Updating the error message in Stage table
----------------------------------------------
IF l_error_lmsg IS NOT NULL
THEN
UPDATE prxl_ar_inv_dist_conv_stg
SET org_id = l_org_id,
customer_id = l_cust_account_id,
customer_site_id = l_cust_site_id,
error_message = l_error_lmsg,
error_code = 'INVALID'
-- batch_source_name = l_new_batch_source_name
WHERE ROWID = cv_valid_rec_lines.ROWID;
ELSE
UPDATE prxl_ar_inv_dist_conv_stg
SET org_id = l_org_id,
customer_id = l_cust_account_id,
customer_site_id = l_cust_site_id,
error_code = 'VALID'
--batch_source_name = l_new_batch_source_name
WHERE ROWID = cv_valid_rec_lines.ROWID;
END IF;
END LOOP; -- for c_line

IF l_error_hmsg IS NOT NULL


THEN
UPDATE prxl_ar_inv_lines_conv_stg
SET error_message = l_error_hmsg,
error_code = 'INVALID',
customer_id = l_cust_account_id,
customer_site_id = l_cust_site_id,
org_id = l_org_id,
term_id = l_term_id,
cust_trx_type_id = l_cust_trx_type_id
-- batch_source_name = l_new_batch_source_name
WHERE ROWID = cv_valid_rec_head.ROWID;

prxl_common_pkg.write_log ('Line Record Error :' || l_error_hmsg);


END IF;

IF l_error_lmsg IS NOT NULL


THEN
UPDATE prxl_ar_inv_lines_conv_stg
SET error_message = error_message || ';' || l_error_lmsg,
error_code = 'INVALID',
customer_id = l_cust_account_id,
customer_site_id = l_cust_site_id,
org_id = l_org_id,
term_id = l_term_id,
cust_trx_type_id = l_cust_trx_type_id
--batch_source_name = l_new_batch_source_name
WHERE ROWID = cv_valid_rec_head.ROWID;
END IF;

IF l_error_lmsg IS NULL AND l_error_hmsg IS NULL


THEN
UPDATE prxl_ar_inv_lines_conv_stg
SET error_code = 'VALID',
customer_id = l_cust_account_id,
customer_site_id = l_cust_site_id,
org_id = l_org_id,
term_id = l_term_id,
cust_trx_type_id = l_cust_trx_type_id
-- batch_source_name = l_new_batch_source_name
WHERE ROWID = cv_valid_rec_head.ROWID;
END IF;
END LOOP; -- for c_head

COMMIT;
-- Call the Generate Report Procedure
prxl_ar_inv_generate_report (p_tot_records_lines => l_tot_records_lines,
p_tot_records_dist => l_tot_records_dist
);
END prxl_ar_inv_conv_valid_proc;

/
***********************************************************************************
**************
||
|| Description : Package procedure used to process valid records into
interface tables
|| and call the standard program
||
|| Called subprograms:
||
|| Ver Date Author Modification
||
|| 1.0 15-APR-09 Narasimha Rao Akula Initial Version
||
***********************************************************************************
****************/
PROCEDURE prxl_ar_inv_conv_process_proc
AS
l_record_count NUMBER := 0;
l_set_of_bks_id NUMBER := fnd_profile.VALUE
('GL_SET_OF_BKS_ID');
l_user_id NUMBER := fnd_profile.VALUE ('USER_ID');
l_line_num NUMBER := 1;
l_dist_num NUMBER := 1;
l_tot_records_lines NUMBER;
l_tot_records_dist NUMBER;
l_wait BOOLEAN;
l_request_id NUMBER;
l_phase VARCHAR2 (2000) := '';
l_status VARCHAR2 (2000) := '';
l_dev_phase VARCHAR2 (2000) := '';
l_dev_status VARCHAR2 (2000) := '';
l_message VARCHAR2 (2000) := '';

CURSOR c_lines
IS
SELECT ROWID,
operating_unit,
batch_source_name,
line_description,
trx_date,
line_amount,
currency_code,
conversion_type,
conversion_rate,
term_name,
customer_id,
customer_site_id,
org_id,
cust_trx_type_id,
trx_number,
term_id,
line_type,
line_number,
gl_date,
attribute2,
attribute3,
attribute4,
attribute9,
attribute12,
attribute13,
attribute14
FROM prxl_ar_inv_lines_conv_stg
WHERE 1 = 1
AND error_code in( 'VALID','UNPROCESSED')
AND ROWNUM <= g_batch_size
ORDER BY trx_number, line_number;

CURSOR c_dist (cp_trx_number VARCHAR2, cp_line_number NUMBER)


IS
SELECT ROWID,
operating_unit,
batch_source_name,
trx_number,
line_number,
account_class,
dist_amount,
segment1,
segment2,
segment3,
segment4,
segment5,
segment6,
segment7,
segment8,
segment9,
org_id,
gl_date,
dist_code_combination_id
-- percent
FROM prxl_ar_inv_dist_conv_stg
WHERE 1 = 1
AND error_code in( 'VALID','UNPROCESSED')
AND trx_number = cp_trx_number
AND line_number = cp_line_number;

-- Declaration of Cursor for Updtaing Staging table for processed records


CURSOR c_upd_lines
IS
SELECT ROWID,
a.trx_number
FROM prxl_ar_inv_lines_conv_stg a
WHERE error_code = 'INTERFACED';

CURSOR c_upd_dist
IS
SELECT ROWID,
b.trx_number
FROM prxl_ar_inv_dist_conv_stg b
WHERE error_code = 'INTERFACED';
BEGIN
--To get the Total Number Line Records to be Processed
SELECT COUNT (1)
INTO l_tot_records_lines
FROM prxl_ar_inv_lines_conv_stg
WHERE error_code = 'VALID';

--To get the Total Number Distribution Records to be Processed


SELECT COUNT (1)
INTO l_tot_records_dist
FROM prxl_ar_inv_dist_conv_stg
WHERE error_code = 'VALID';

FOR cv_process_rec_lines IN c_lines


LOOP
INSERT INTO ra_interface_lines_all
(batch_source_name,
set_of_books_id,
line_type,
description,
currency_code,
amount,
cust_trx_type_id,
trx_date,
orig_system_batch_name,
conversion_type,
conversion_rate,
org_id,
created_by,
creation_date,
last_updated_by,
last_update_date,
interface_line_context,
header_attribute1,
interface_line_attribute1,
interface_line_attribute2,
trx_number,
term_id,
orig_system_bill_customer_id,
orig_system_bill_address_id,
gl_date,
line_number,
quantity,
--tax_code,
attribute2,
attribute3,
attribute4,
attribute9,
attribute12,
attribute13,
attribute14
)
VALUES (cv_process_rec_lines.batch_source_name, --
batch_source_name
l_set_of_bks_id, --
set_of_books_id
cv_process_rec_lines.line_type, -- line_type
cv_process_rec_lines.line_description, -- description
cv_process_rec_lines.currency_code, --
currency_code
cv_process_rec_lines.line_amount, -- amount
cv_process_rec_lines.cust_trx_type_id, --
cust_trx_type_id
cv_process_rec_lines.trx_date, -- trx_date
cv_process_rec_lines.batch_source_name, --
orig_system_batch_name
cv_process_rec_lines.conversion_type, --
conversion_type
cv_process_rec_lines.conversion_rate, --
conversion_rate
cv_process_rec_lines.org_id, -- org_id
l_user_id, -- created_by
SYSDATE, --
creation_date
l_user_id, --
last_updated_by
SYSDATE , --
last_update_date
cv_process_rec_lines.batch_source_name, --
interface_line_context
cv_process_rec_lines.trx_number, --
header_attribute1
cv_process_rec_lines.trx_number, --
interface_line_attribute1
cv_process_rec_lines.line_number, --
interface_line_attribute2
cv_process_rec_lines.trx_number, -- trx_number
cv_process_rec_lines.term_id, -- term_id
cv_process_rec_lines.customer_id, --
orig_system_bill_customer_id
cv_process_rec_lines.customer_site_id, --
orig_system_bill_address_id
g_gl_date,
--cv_process_rec_lines.gl_date, -- gl_date
cv_process_rec_lines.line_number, -- line_number
1, -- quantity
--'UK_VAT', --tax_code
cv_process_rec_lines.attribute2,
cv_process_rec_lines.attribute3,
cv_process_rec_lines.attribute4,
cv_process_rec_lines.attribute9,
cv_process_rec_lines.attribute12,
cv_process_rec_lines.attribute13,
cv_process_rec_lines.attribute14
);

IF SQL%FOUND
THEN
UPDATE prxl_ar_inv_lines_conv_stg
SET error_code = 'INTERFACED'
WHERE ROWID = cv_process_rec_lines.ROWID;
ELSE
UPDATE prxl_ar_inv_lines_conv_stg
SET error_code = 'NOTINTERFACED'
WHERE ROWID = cv_process_rec_lines.ROWID;
END IF;

FOR cv_process_rec_dist IN c_dist (cv_process_rec_lines.trx_number,


cv_process_rec_lines.line_number
)
LOOP
INSERT INTO ra_interface_distributions_all
(interface_line_context,
interface_line_attribute1,
interface_line_attribute2,
account_class,
amount,
percent,
--code_combination_id,
segment1,
segment2,
segment3,
segment4,
segment5,
segment6,
segment7,
segment8,
segment9,
org_id,
created_by,
creation_date,
last_updated_by,
last_update_date
)
VALUES (cv_process_rec_dist.batch_source_name, --
interface_line_context
cv_process_rec_dist.trx_number, --
interface_line_attribute1
cv_process_rec_dist.line_number, --
interface_line_attribute2
cv_process_rec_dist.account_class, --
account_class
cv_process_rec_dist.dist_amount, -- amount
=(unit_selling_price*quantity_invoiced)
100, -- percent
-- cv_process_rec_dist.dist_code_combination_id, --
code_combination_id
cv_process_rec_dist.segment1,
cv_process_rec_dist.segment2,
cv_process_rec_dist.segment3,
cv_process_rec_dist.segment4,
cv_process_rec_dist.segment5,
cv_process_rec_dist.segment6,
cv_process_rec_dist.segment7,
cv_process_rec_dist.segment8,
cv_process_rec_dist.segment9,
cv_process_rec_dist.org_id, -- org_id
l_user_id, --
created_by
SYSDATE, --
creation_date
l_user_id, --
last_updated_by
SYSDATE --
last_update_date
);

l_dist_num := l_dist_num + 1;

IF SQL%FOUND
THEN
UPDATE prxl_ar_inv_dist_conv_stg
SET error_code = 'INTERFACED'
WHERE ROWID = cv_process_rec_dist.ROWID;
ELSE
UPDATE prxl_ar_inv_dist_conv_stg
SET error_code = 'NOTINTERFACED'
WHERE ROWID = cv_process_rec_dist.ROWID;
END IF;
END LOOP;
END LOOP;

-------------------------------------------------------------------
-- Run Auto Invoice to upload data into Oracle Receivables
-------------------------------------------------------------------

IF l_dist_num > 0
THEN
l_request_id :=
fnd_request.submit_request
('AR',
'RAXTRX',
'Auto Invoice Import Program',
NULL,
FALSE,
'MAIN',
'T',
1001,
'CONVERSION', -- Parameter Data source
SYSDATE,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
'N',
'Y',
NULL,
85, --FND_GLOBAL.ORG_ID,
CHR (0)
);
COMMIT;

LOOP
l_wait :=
fnd_concurrent.get_request_status (l_request_id,
'AR',
'RAXTRX',
l_phase,
l_status,
l_dev_phase,
l_dev_status,
l_message
);

IF l_dev_phase = 'COMPLETE'
THEN
EXIT;
END IF;
END LOOP;

prxl_common_pkg.write_log ( 'The request '


|| l_request_id
|| ' is '
|| l_dev_phase
|| ' with '
|| l_dev_status
);
END IF;

FOR c_upd_lines_rec IN c_upd_lines


LOOP
UPDATE prxl_ar_inv_lines_conv_stg stgl
SET error_code = 'PROCESSED'
WHERE 1 = 1
AND ROWID = c_upd_lines_rec.ROWID
AND EXISTS (
SELECT 1
FROM ra_customer_trx_all rct, ra_customer_trx_lines_all rctl
WHERE 1 = 1
AND rct.customer_trx_id = rctl.customer_trx_id
AND stgl.trx_number = rct.trx_number
AND stgl.line_number = rctl.interface_line_attribute2
AND stgl.org_id = rct.org_id);

UPDATE prxl_ar_inv_lines_conv_stg stgl


SET error_code = 'UNPROCESSED'
WHERE 1 = 1
AND ROWID = c_upd_lines_rec.ROWID
AND NOT EXISTS (
SELECT 1
FROM ra_customer_trx_all rct, ra_customer_trx_lines_all rctl
WHERE 1 = 1
AND rct.customer_trx_id = rctl.customer_trx_id
AND stgl.trx_number = rct.trx_number
AND stgl.line_number = rctl.interface_line_attribute2
AND stgl.org_id = rct.org_id);
END LOOP;

FOR c_upd_dist_rec IN c_upd_dist


LOOP
UPDATE prxl_ar_inv_dist_conv_stg stgd
SET error_code = 'PROCESSED'
WHERE 1 = 1
AND ROWID = c_upd_dist_rec.ROWID
AND EXISTS (
SELECT 1
FROM ra_customer_trx_all rct,
ra_customer_trx_lines_all rctl,
ra_cust_trx_line_gl_dist_all rctd
WHERE 1 = 1
AND rct.customer_trx_id = rctl.customer_trx_id
AND rctl.customer_trx_line_id = rctd.customer_trx_line_id
AND stgd.trx_number = rct.trx_number
AND stgd.line_number = rctl.interface_line_attribute2
AND stgd.org_id = rct.org_id);

UPDATE prxl_ar_inv_dist_conv_stg stgd


SET error_code = 'UNPROCESSED'
WHERE 1 = 1
AND ROWID = c_upd_dist_rec.ROWID
AND NOT EXISTS (
SELECT 1
FROM ra_customer_trx_all rct,
ra_customer_trx_lines_all rctl,
ra_cust_trx_line_gl_dist_all rctd
WHERE 1 = 1
AND rct.customer_trx_id = rctl.customer_trx_id
AND rctl.customer_trx_line_id = rctd.customer_trx_line_id
AND stgd.trx_number = rct.trx_number
AND stgd.line_number = rctl.interface_line_attribute2
AND stgd.org_id = rct.org_id);
END LOOP;

COMMIT;
-- call generate procedure
prxl_ar_inv_generate_report (p_tot_records_lines => l_tot_records_lines,
p_tot_records_dist => l_tot_records_dist
);
END prxl_ar_inv_conv_process_proc;

/
***********************************************************************************
****************************
||
|| Description : Main Procedure to be called from Conncurent Program to
Load/Validate/Process or All
||
|| Ver Date Author Modification
||
|| 1.0 15-APR-09 Narasimha Rao Akula Initial Version
||
***********************************************************************************
******************************/
PROCEDURE prxl_ar_inv_conv_main_proc (
errbuf OUT NOCOPY VARCHAR2,
retcode OUT NOCOPY VARCHAR2,
p_conv_opt IN VARCHAR2,
p_batch_size IN NUMBER,
p_gl_date IN DATE
)
AS
-- Local Variables required for Procedure
l_return_status VARCHAR2 (1);
l_return_message VARCHAR2 (2000);
l_str VARCHAR2 (1000) := '************************';
BEGIN
prxl_common_pkg.write_output (l_str || ' AR INVOICES CONVERSION *' || l_str);
prxl_common_pkg.write_output ( 'Report Run Date : '
|| TO_CHAR (SYSDATE, 'MM-DD-RRRR')
);
prxl_common_pkg.write_output ('Conversion Parameter : ' || p_conv_opt);
g_conv_opt := p_conv_opt;
g_batch_size := p_batch_size;
g_gl_date := p_gl_date;

IF p_conv_opt = 'LOAD'
THEN
prxl_ar_inv_conv_load_proc;
ELSIF p_conv_opt = 'VALIDATE'
THEN
prxl_ar_inv_conv_valid_proc;
ELSIF p_conv_opt = 'PROCESS'
THEN
prxl_ar_inv_conv_process_proc;
ELSIF p_conv_opt = 'ALL'
THEN
g_conv_opt := 'LOAD';
prxl_ar_inv_conv_load_proc;
g_conv_opt := 'VALIDATE';
prxl_ar_inv_conv_valid_proc;
g_conv_opt := 'PROCESS';
prxl_ar_inv_conv_process_proc;
END IF;
EXCEPTION
WHEN OTHERS
THEN
prxl_common_pkg.write_log
( 'AR Invoices Creation Error--Main Procedure ; '
|| SUBSTR (l_return_message, 4)
|| SQLERRM
);
END prxl_ar_inv_conv_main_proc;
END prxl_ar_inv_conv_pkg;

You might also like