Professional Documents
Culture Documents
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;
/
***********************************************************************************
*******************
||
|| 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);
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);
/
***********************************************************************************
************************
||
|| 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;
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';
-------------------------------
-- 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;
--------------------------------------
--- Distribution Data Validation
--------------------------------------
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;
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_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';
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;
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;
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;