0% found this document useful (0 votes)
175 views50 pages

1

This document contains the code for a package body in PL/SQL that is used for employee supplier synchronization. The package body defines variables, constants, cursors and other program logic to fetch employee data from HRMS and create or update corresponding supplier records in payables by synchronizing the data.

Uploaded by

sreekantth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views50 pages

1

This document contains the code for a package body in PL/SQL that is used for employee supplier synchronization. The package body defines variables, constants, cursors and other program logic to fetch employee data from HRMS and create or update corresponding supplier records in payables by synchronizing the data.

Uploaded by

sreekantth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 50

CREATE OR REPLACE PACKAGE BODY APPS.

xxcdm_ap_empsup_ext_pkg
AS
/*

===================================================================================
====
||
||
|| PL/SQL Code
||
||
||
|| Filename : xxcdm_ap_empsup_ext_pkg.pkb
||
||
||
|| Code Type: Package body
||
||
||
|| Author : Saurabh Kumar
||
||
||
|| Purpose : Package body for employee supplier synchronization program
||
||
||
|| Copyright: CDM Smith All rights reserved.
||
||
||
|| Version History:
||
||
||
|| Name Version Reason for Change Date
||
|| ------------------ ------- ------------------------------------
----------- ||
|| Saurabh Kumar 1.0 Initial Creation 10-Feb-
2016 ||
|| Saurabh Kumar 2.0 FOT Changes 14-Mar-
2016 ||
|| a)Output modified to contain created
||
|| /updated numbers
||
|| Arun Gopalan 3.0 Accomodate Setup Changes in deriving 17-Mar-
2016 ||
|| WG and LE and Acct FFF names in code
||
|| Saurabh Kumar 4.0 Corrected Changes done by Arun 18-Mar-
2016 ||
|| Saurabh Kumar 5.0 INT CR # 570 Changes 18-May-
2016 ||
|| a)Identify international employees
||
|| b)Set site inactive date for OU
||
|| change as sysdate + 21
||
|| Saurabh Kumar 6.0 PROD CR # 2055 Changes 24-Aug-
2016 ||
|| a)Consider actual_termination_date for
terminated ||
|| Employees in place of final_process_date
||
|| b)Skip employees with assignment organization
||
|| defined in the lookup
||
|| "CDM_NON_US_DUMMY_ORG"
||
|| c)Error report to display details of all
employees||
|| d)Added address primary flag "Y" to avoid
double ||
|| processing
||
|| e)Logic to ignore Adhoc request runs with
employee||
|| id parameter while fetch last run date
||
|| f)During site ou change end date current ou
sites ||
|| with sysdate
||
||Vibhor Rastogi 7.0 Default Payment Method update
||
||Naresh Mallela 8.0 Modified as part of EU R12 Rollout

===================================================================================
====
*/
gv_business_process_name VARCHAR2 (240)
:= 'CDM Payables Employee Supplier Extension Program';
gv_business_process_entity VARCHAR2 (240) := 'Employee';
gv_business_process_domain VARCHAR2 (240) := 'Payables';
gv_source VARCHAR2 (240) := 'EBS HRMS';
g_debug_switch VARCHAR2 (1) := 'Y';
gd_last_run_date DATE
:= TO_DATE ('01-JAN-1900'
, 'DD-MON-RRRR');

gn_current_log_level CONSTANT NUMBER := 1; --fnd_profile.VALUE ('AFLOG_LEVEL');


gn_statement CONSTANT NUMBER := 1;
gn_procedure CONSTANT NUMBER := 2;
gn_event CONSTANT NUMBER := 3;
gn_exception CONSTANT NUMBER := 4;
gn_error CONSTANT NUMBER := 5;
gn_unexpected CONSTANT NUMBER := 6;
gn_user_id NUMBER := fnd_global.user_id;
gn_login_id NUMBER := fnd_global.login_id;
--------------------14-Mar-16 ------------------
gn_resp_id NUMBER := fnd_global.resp_id;
gn_resp_appl_id NUMBER := fnd_global.resp_appl_id;
gn_create_failseedval_records NUMBER := 0;
gn_create_failcustval_records NUMBER := 0;
gn_update_failseedval_records NUMBER := 0;
gn_update_failcustval_records NUMBER := 0;
gn_create_processed_records NUMBER := 0;
gn_update_processed_records NUMBER := 0;
gn_update_total_records NUMBER := 0;
gn_create_total_records NUMBER := 0;

--------------------14-Mar-16 ------------------
--------------------24-Aug-16 ------------------
gn_total_skipped_records NUMBER := 0;
--------------------24-Aug-16 ------------------
gn_total_records NUMBER := 0;
gn_total_processed_records NUMBER := 0;
gn_total_failcustval_records NUMBER := 0;
gn_total_failseedval_records NUMBER := 0;

gv_remit_advice_del_method VARCHAR2 (240);


gv_create_operation VARCHAR2 (240) := 'CREATE';
gv_update_operation VARCHAR2 (240) := 'UPDATE';
gv_yes VARCHAR2 (1) := 'Y';
gv_no VARCHAR2 (1) := 'N';
gv_le_value_set_name VARCHAR2 (240);
gv_wg_value_set_name VARCHAR2 (240);
gv_owg_value_set_name VARCHAR2 (240);
gv_error_status VARCHAR2 (1) := 'E';
gv_success_status VARCHAR2 (1) := 'S';

gv_intercompany_segment VARCHAR2 (240);


gv_future1_segment VARCHAR2 (240);
gv_future2_segment VARCHAR2 (240);

gv_enabled_flag fnd_lookup_values.description%TYPE;
gv_match_option fnd_lookup_values.description%TYPE;
gv_payment_method_lookup_code fnd_lookup_values.description%TYPE;
gv_payment_priority fnd_lookup_values.description%TYPE;
gv_payment_priority_site fnd_lookup_values.description%TYPE;
gv_payment_term fnd_lookup_values.description%TYPE;
gv_payment_term_site fnd_lookup_values.description%TYPE;
gv_pay_dte_basis_lkp_code fnd_lookup_values.description%TYPE;
gv_pay_dte_basis_lkp_codesite fnd_lookup_values.description%TYPE;
gv_pay_group_lookup_code fnd_lookup_values.description%TYPE;
gv_pay_group_lookup_code_site fnd_lookup_values.description%TYPE;
gv_pay_site_flag fnd_lookup_values.description%TYPE;
gv_vendor_type_lookup_code fnd_lookup_values.description%TYPE;
gn_payment_term_id NUMBER;
gn_payment_term_site_id NUMBER;

gv_flex_code fnd_id_flex_structures.id_flex_code%TYPE;
gv_flex_appl fnd_application.application_short_name%TYPE;
gv_flex_structure_code fnd_id_flex_structures.id_flex_structure_code
%TYPE;
-----------------------18-May-16 ------------------------
gv_intrim_ou_name VARCHAR2 (240) := NULL;

-----------------------18-May-16 ------------------------
/**********************************************************************************
Name : cur_emp_vendor
Purpose : Cursor to fetch employees to be created as vendors

**********************************************************************************/

CURSOR cur_emp_vendor (
pn_person_id NUMBER DEFAULT NULL
, pd_record_date DATE DEFAULT NULL)
IS
SELECT paf.assignment_id
, ppf.person_id
, ppf.party_id
, ppf.known_as
, ppf.employee_number
, pbg.legislation_code
, pbg.name bg
, ppf.last_name
|| ', '
|| ppf.first_name
|| DECODE (ppf.middle_names, NULL, '', ' ')
|| ppf.middle_names
vendor_name --full_name
, ppf.email_address
, (SELECT actual_termination_date --final_process_date --Changed by
Saurabh on 24-Aug-16
FROM per_periods_of_service pos
WHERE person_id = ppf.person_id
AND date_start = (SELECT MAX (pos2.date_start)
FROM per_periods_of_service pos2
WHERE pos2.person_id = pos.person_id
AND pos2.date_start <= SYSDATE))
inactive_date
, CASE
WHEN ppf.original_date_of_hire < pps.date_start THEN 'Y'
ELSE 'N'
END
re_hire_flag
, ppf.last_update_date
, paf.set_of_books_id
, ppf.attribute10
, ppf.attribute11
, paf.default_code_comb_id
, ppf.business_group_id
, paf.ass_attribute3
, paf.people_group_id
, paf.organization_id
, ppf.attribute2
, NULL location_code
, pa.address_line1 address_line_1
, pa.address_line2 address_line_2
, pa.address_line3 address_line_3
, pa.town_or_city city
, pa.style
, DECODE (pa.style
, 'CA', ''
, 'CA_GLB', ''
, NVL (pa.region_2, ''))
state
, pa.postal_code postal_code
, DECODE (pa.style
, 'US', ''
, 'US_GLB', ''
, 'IE', ''
, 'IE_GLB', ''
, 'GB', ''
, 'CA', NVL (pa.region_1, '')
, 'JP', NVL (pa.region_1, '')
, NVL (ap_web_db_expline_pkg.getcountyprovince (pa.style
, pa.region_1)
, ''))
province
, DECODE (pa.style
, 'US', NVL (pa.region_1, '')
, 'US_GLB', NVL (pa.region_1, '')
, 'IE', NVL (ap_web_db_expline_pkg.getcountyprovince (
pa.style
, pa.region_1)
, '')
, 'IE_GLB', NVL (ap_web_db_expline_pkg.getcountyprovince (
pa.style
, pa.region_1)
, '')
, 'GB', NVL (ap_web_db_expline_pkg.getcountyprovince (
pa.style
, pa.region_1)
, '')
, '')
county
, pa.country
, pa.address_id
, paf.ass_attribute8 emp_payment_mthod
FROM per_all_people_f ppf
, per_all_assignments_f paf
, per_periods_of_service pps
, per_business_groups pbg
, per_addresses pa
WHERE ppf.person_id = paf.person_id
AND paf.assignment_type = ('E')
AND ppf.business_group_id = pbg.business_group_id
AND paf.primary_flag = 'Y'
AND pa.primary_flag(+) = 'Y' --Added by Saurabh on 24-Aug-16
AND pa.person_id(+) = ppf.person_id
AND SYSDATE BETWEEN NVL (pa.date_from, SYSDATE)
AND NVL (pa.date_to, SYSDATE)
AND pps.person_id = ppf.person_id
AND pps.date_start = (SELECT MAX (pos2.date_start)
FROM per_periods_of_service pos2
WHERE pos2.person_id = pps.person_id
AND pos2.date_start <= TRUNC (SYSDATE))
AND TRUNC (NVL (pps.actual_termination_date -- final_process_date --Changed
by Saurabh on 24-Aug-16
, SYSDATE)) BETWEEN
ppf.effective_start_date
AND
ppf.effective_end_date
AND TRUNC (NVL (pps.actual_termination_date -- final_process_date --Changed
by Saurabh on 24-Aug-16
, SYSDATE)) BETWEEN
paf.effective_start_date
AND
paf.effective_end_date
AND ppf.person_id = NVL (pn_person_id, ppf.person_id)
AND ppf.employee_number IS NOT NULL
AND (ppf.last_update_date >= NVL (pd_record_date, gd_last_run_date)
OR paf.last_update_date >= NVL (pd_record_date, gd_last_run_date));

/**********************************************************************************
Name : output
Purpose : Procedure to print messages in the output of the concurrent
program
Input Parameters: pv_msg -> String message to print on standard output
Output Parameters:

***********************************************************************************
*/
PROCEDURE output (pv_msg IN VARCHAR2)
IS
BEGIN
IF gn_login_id = -1
THEN
DBMS_OUTPUT.put_line (pv_msg);
ELSE
fnd_file.put_line (fnd_file.output
, pv_msg);
END IF;
END output;

/**********************************************************************************
Name : log
Purpose : Procedure to print messages in the log of the concurrent
program
Input Parameters: pv_msg -> String message to print on standard log
Output Parameters:

***********************************************************************************
*/
PROCEDURE LOG (pv_msg IN VARCHAR2)
IS
BEGIN
IF gn_login_id = -1
THEN
DBMS_OUTPUT.put_line (pv_msg);
ELSE
fnd_file.put_line (fnd_file.LOG
, pv_msg);
END IF;
END LOG;

/**********************************************************************************
Name : debug
Purpose : Procedure to print, based on current log level
messages in the log of the concurrent program
Input Parameters: pn_debug_level -> Debug level on which message needs to be
printed
pv_msg -> String message to print on standard log
Output Parameters:

***********************************************************************************
*/

PROCEDURE debug (pn_debug_level IN NUMBER DEFAULT 6


, pv_msg IN VARCHAR2)
IS
BEGIN
IF gn_current_log_level <= pn_debug_level
THEN
LOG (pv_msg);
END IF;
END debug;

-------------------24-Aug-16 ------------------------

/**********************************************************************************
Name : check_org_exclusion
Purpose : Function to check if the employee assignment organization
exists
in the exclusion Lookup "CDM_NON_US_DUMMY_ORG"
Input Parameters: pv_organization_name -> Organization Name
Return: BOOLEAN

***********************************************************************************
*/

FUNCTION check_org_exclusion (pv_organization_name IN VARCHAR2)


RETURN BOOLEAN
IS
lv_check NUMBER;
BEGIN
debug (gn_statement
, 'check_org_exclusion (+)');

SELECT 1
INTO lv_check
FROM fnd_lookup_values flv
WHERE flv.lookup_type = 'CDM_NON_US_DUMMY_ORG'
AND flv.description = pv_organization_name
AND flv.language = 'US' --USERENV ('LANG') --8.0
AND NVL (flv.enabled_flag, 'N') = 'Y'
AND TRUNC (SYSDATE) BETWEEN NVL (flv.start_date_active
, TRUNC (SYSDATE))
AND NVL (flv.end_date_active, TRUNC (SYSDATE));

debug (gn_statement
, 'check_org_exclusion (-)');
RETURN TRUE;
EXCEPTION
WHEN OTHERS
THEN
debug (gn_statement
, 'check_org_exclusion (-)');
RETURN FALSE;
END check_org_exclusion;
-------------------24-Aug-16 ------------------------

/*************************************************************************
*
* PROCEDURE: get_last_run_date_time
*
* DESCRIPTION: Procedure to set last successful request's
* request date as start date
*************************************************************************/

PROCEDURE get_last_run_date_time
IS
ln_conc_request_id NUMBER := fnd_global.conc_request_id;
BEGIN
debug (gn_statement
, 'get_last_run_date_time(+)');

SELECT MAX (fcr.actual_start_date)


INTO gd_last_run_date
FROM fnd_concurrent_requests fcr
WHERE fcr.concurrent_program_id =
(SELECT fcr1.concurrent_program_id
FROM fnd_concurrent_requests fcr1
WHERE fcr1.request_id = ln_conc_request_id)
AND fcr.argument1 IS NULL --Added by Saurabh on 24-Aug-16
AND fcr.phase_code = 'C'
AND fcr.status_code = 'C';

debug (gn_statement
, 'get_last_run_date_time(-)');
EXCEPTION
WHEN OTHERS
THEN
debug (gn_unexpected
, 'Error in get_last_run_date_time: ' || SQLERRM);
END get_last_run_date_time;

/**********************************************************************************
Name : get_org_id
Purpose : Function to fetch org_id from legal entity
Input Parameters: pv_legal_entity -> Legal entity name
Return: NUMBER

***********************************************************************************
*/

FUNCTION get_org_id (pv_legal_entity IN VARCHAR2)


RETURN NUMBER
IS
lv_legal_entity_name VARCHAR2 (240) := NULL;
ln_org_id NUMBER := NULL;
lv_ou_name VARCHAR2 (240) := NULL; --Added by Saurabh on 18-May-16
BEGIN
debug (gn_statement
, 'get_org_id (+)');

SELECT le.name
, o.organization_id
, o.name --Added by Saurabh on 18-May-16
INTO lv_legal_entity_name
, ln_org_id
, lv_ou_name --Added by Saurabh on 18-May-16
FROM xle_etb_profiles establishmenteo
, xle_entity_profiles le
, xle_associations legalassociationseo
, xle_association_types atype
, xle_assoc_object_types ctype_obj
, xle_assoc_object_types ctype_sub
, hr_all_organization_units o
, gl_legal_entities_bsvs glev
WHERE establishmenteo.legal_entity_id = le.legal_entity_id
AND atype.association_type_id =
legalassociationseo.association_type_id
AND atype.object_type_id = ctype_obj.object_type_id
AND atype.subject_type_id = ctype_sub.object_type_id
AND atype.context = 'TAX_CALCULATION'
AND ctype_sub.name = 'ESTABLISHMENT'
AND ctype_obj.name = 'OPERATING_UNIT'
AND legalassociationseo.subject_id = establishmenteo.establishment_id
AND legalassociationseo.object_id = o.organization_id
AND glev.legal_entity_id = le.legal_entity_id
AND glev.flex_segment_value = pv_legal_entity;

-------------------18-May-16 ------------------------
IF lv_ou_name = gv_intrim_ou_name
THEN
ln_org_id := -1;
END IF;

-------------------18-May-16 ------------------------
debug (gn_statement
, 'org_id: ' || ln_org_id);
debug (gn_statement
, 'get_org_id (-)');
RETURN ln_org_id;
EXCEPTION
WHEN OTHERS
THEN
debug (gn_unexpected
, 'Error in get_org_id: ' || SQLERRM);
RETURN NULL;
END get_org_id;

/**********************************************************************************
Name : get_le_wg_details
Purpose : Procedure to fetch legal entity and work group details based
on
organization name
Input Parameters: pn_organization_id NUMBER
Output Parameters: xv_legal_entity VARCHAR2, xv_workgroup VARCHAR2

***********************************************************************************
*/

PROCEDURE get_le_wg_details (pn_organization_id IN NUMBER


, xv_organization_name OUT VARCHAR2
, xv_legal_entity OUT VARCHAR2
, xv_workgroup OUT VARCHAR2)
IS
lv_organization_name VARCHAR2 (240) := NULL;
lv_legal_entity VARCHAR2 (240) := NULL;
lv_workgroup VARCHAR2 (240) := NULL;
BEGIN
debug (gn_statement
, 'get_le_wg_details (+)');

/* SELECT o.name
, SUBSTR (o.name
, INSTR (o.name
, '.'
, -1)
- 3
, 3)
, SUBSTR (o.name
, INSTR (o.name
, '.'
, -1)
+ 1
, 6)
INTO lv_organization_name
, lv_legal_entity
, lv_workgroup
FROM hr_all_organization_units o
WHERE o.organization_id = pn_organization_id;*/
--Added by Arun due to change in logic of LE and WG derivation due to setup
change
SELECT hou.name
, SUBSTR (org_information3
, 1
, 3)
, org_information4
INTO lv_organization_name
, lv_legal_entity
, lv_workgroup
FROM apps.hr_organization_information hoi
, hr_all_organization_units hou
WHERE 1 = 1
AND hoi.org_information_context(+) = 'CDM Workgroup Attributes'
AND hoi.organization_id(+) = hou.organization_id
AND hou.organization_id = pn_organization_id;

debug (gn_statement
, 'lv_organization_name: ' || lv_organization_name);
debug (gn_statement
, 'lv_workgroup: ' || lv_workgroup);
debug (gn_statement
, 'lv_legal_entity: ' || lv_legal_entity);
xv_legal_entity := lv_legal_entity;
xv_workgroup := lv_workgroup;
xv_organization_name := lv_organization_name;
debug (gn_statement
, 'get_le_wg_details (-)');
EXCEPTION
WHEN OTHERS
THEN
xv_legal_entity := NULL;
xv_workgroup := NULL;
xv_organization_name := NULL;
debug (gn_unexpected
, 'Error in get_le_wg_details: ' || SQLERRM);
END get_le_wg_details;

/**********************************************************************************
Name : check_segment
Purpose : Function to validate chart of account segments from value set
Input Parameters: pv_flex_value_set_name VARCHAR2
pv_flex_value IN VARCHAR2
Output Parameters:

***********************************************************************************
*/

FUNCTION check_segment (pv_flex_value_set_name IN VARCHAR2


, pv_flex_value IN VARCHAR2)
RETURN BOOLEAN
IS
ln_dummy NUMBER;
BEGIN
SELECT 1
INTO ln_dummy
FROM DUAL
WHERE EXISTS
(SELECT 1
FROM fnd_flex_values_vl ffvv
, fnd_flex_value_sets ffvs
WHERE ( ('' IS NULL)
OR (ffvv.structured_hierarchy_level IN (SELECT hierarchy_id
FROM
fnd_flex_hierarchies_vl h
WHERE
h.flex_value_set_id =

ffvs.flex_value_set_id
AND h.hierarchy_name
LIKE
'')))
AND (ffvv.flex_value_set_id = ffvs.flex_value_set_id)
AND ffvs.flex_value_set_name = pv_flex_value_set_name --'AFF WG'
AND ffvv.flex_value = pv_flex_value);

RETURN TRUE;
EXCEPTION
WHEN OTHERS
THEN
debug (gn_unexpected
, 'Error in check_segment: ' || SQLERRM);
RETURN FALSE;
END check_segment;

/**********************************************************************************
Name : get_code_combinations
Purpose : Procedure to fetch legal entity and work group details based
on
organization name
Input Parameters: pn_organization_id NUMBER
Output Parameters: xv_legal_entity VARCHAR2, xv_workgroup VARCHAR2

***********************************************************************************
*/

PROCEDURE get_code_combinations (pv_legal_entity IN VARCHAR2


, pv_workgroup IN VARCHAR2
, pn_org_id IN NUMBER
, xn_liability_ccid OUT NUMBER
, xn_prepay_ccid OUT NUMBER
, xv_error_message OUT VARCHAR2)
IS
lv_organization_name VARCHAR2 (240) := NULL;
lv_legal_entity VARCHAR2 (240) := NULL;
lv_workgroup VARCHAR2 (240) := NULL;
lv_prepay_account VARCHAR2 (240) := NULL;
lv_liability_account VARCHAR2 (240) := NULL;
lv_liability_segments VARCHAR2 (240) := NULL;
lv_prepay_segments VARCHAR2 (240) := NULL;
ln_liability_ccid NUMBER := NULL;
ln_prepay_ccid NUMBER := NULL;
ln_structure_num fnd_id_flex_structures.id_flex_num%TYPE := NULL;
le_exception EXCEPTION;
BEGIN
debug (gn_statement
, 'get_code_combinations (+)');

BEGIN
SELECT gcc_prepay.segment2 prepay_account
, gcc_liability.segment2 liability_account
INTO lv_prepay_account
, lv_liability_account
FROM gl_code_combinations gcc_liability
, gl_code_combinations gcc_prepay
, financials_system_params_all fspa
WHERE fspa.prepay_code_combination_id = gcc_prepay.code_combination_id
AND fspa.accts_pay_code_combination_id =
gcc_liability.code_combination_id
AND fspa.org_id = pn_org_id;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
xn_liability_ccid := NULL;
xn_prepay_ccid := NULL;
xv_error_message :=
'Default prepay and liability accounts not defined in system parameters';
RAISE le_exception;
WHEN OTHERS
THEN
xn_liability_ccid := NULL;
xn_prepay_ccid := NULL;
xv_error_message :=
'Error while fetching default prepay and liability accounts from
system parameters'
|| SQLERRM;
RAISE le_exception;
END;

BEGIN
SELECT id_flex_num
INTO ln_structure_num
FROM fnd_id_flex_structures
WHERE id_flex_code = gv_flex_code
AND id_flex_structure_code = gv_flex_structure_code;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
xn_liability_ccid := NULL;
xn_prepay_ccid := NULL;
xv_error_message :=
'COA Flexfield structure '
|| gv_flex_structure_code
|| ' not defined';
RAISE le_exception;
WHEN OTHERS
THEN
xn_liability_ccid := NULL;
xn_prepay_ccid := NULL;
xv_error_message :=
'Error while fetching COA Flexfield structure num for '
|| gv_flex_structure_code
|| ' : '
|| SQLERRM;
RAISE le_exception;
END;

--======================================================================
-- Concatenated segments
--======================================================================
lv_liability_segments :=
pv_legal_entity
|| '.'
|| lv_liability_account
|| '.'
|| pv_workgroup
|| '.'
|| pv_workgroup
|| '.'
|| gv_intercompany_segment
|| '.'
|| gv_future1_segment
|| '.'
|| gv_future2_segment;
debug (gn_statement
, 'lv_liability_segments: ' || lv_liability_segments);
--======================================================================
-- Concatenated segments
--======================================================================
lv_prepay_segments :=
pv_legal_entity
|| '.'
|| lv_prepay_account
|| '.'
|| pv_workgroup
|| '.'
|| pv_workgroup
|| '.'
|| gv_intercompany_segment
|| '.'
|| gv_future1_segment
|| '.'
|| gv_future2_segment;
debug (gn_statement
, 'lv_prepay_segments: ' || lv_prepay_segments);
--======================================================================
-- API to return code combination ID from concatenated segments
--======================================================================
ln_liability_ccid :=
fnd_flex_ext.get_ccid (gv_flex_appl
, gv_flex_code
, ln_structure_num
, TO_CHAR (SYSDATE
, 'YYYY/MM/DD HH24:MI:SS')
, lv_liability_segments);

--Added by Saurabh on 18-Mar-16


IF ln_liability_ccid <= 0
THEN
xv_error_message :=
'Liability account creation failed with ' || fnd_flex_ext.GET_MESSAGE;
END IF;

--Added by Saurabh on 18-Mar-16


--======================================================================
-- API to return code combination ID from concatenated segments
--======================================================================
ln_prepay_ccid :=
fnd_flex_ext.get_ccid (gv_flex_appl
, gv_flex_code
, ln_structure_num
, TO_CHAR (SYSDATE
, 'YYYY/MM/DD HH24:MI:SS')
, lv_prepay_segments);

--Added by Saurabh on 18-Mar-16


IF ln_prepay_ccid <= 0
THEN
xv_error_message :=
xv_error_message
|| 'Prepay account creation failed with '
|| fnd_flex_ext.GET_MESSAGE;
END IF;

--Added by Saurabh on 18-Mar-16


xn_liability_ccid := ln_liability_ccid;
xn_prepay_ccid := ln_prepay_ccid;
debug (gn_statement
, 'xn_liability_ccid: ' || xn_liability_ccid);
debug (gn_statement
, 'xn_prepay_ccid: ' || xn_prepay_ccid);
debug (gn_statement
, 'get_code_combinations (-)');
EXCEPTION
WHEN le_exception
THEN
debug (gn_unexpected
, xv_error_message);
WHEN OTHERS
THEN
xn_liability_ccid := NULL;
xn_prepay_ccid := NULL;
debug (gn_unexpected
, 'Error in get_code_combinations: ' || SQLERRM);
xv_error_message := 'Error in get_code_combinations: ' || SQLERRM;
END get_code_combinations;

/**********************************************************************************
Name : initialize_global_variables
Purpose : Procedure to initialize variables based on
XXCDM_AP_EMPSUP_EXT_DEFAULTS
lookup
Input Parameters:
Output Parameters:

***********************************************************************************
*/

PROCEDURE initialize_global_variables
IS
BEGIN
debug (gn_statement
, 'initialize_global_variables (+)');
gv_enabled_flag :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'ENABLED_FLAG')
, 'Y');
gv_match_option :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'MATCH_OPTION')
, 'P');
gv_payment_method_lookup_code :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'PAYMENT_METHOD_LOOKUP_CODE')
, 'CHECK');
gv_payment_priority :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'PAYMENT_PRIORITY')
, '99');
gv_payment_priority_site :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'PAYMENT_PRIORITY_SITE')
, '99');
gv_payment_term :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'PAYMENT_TERM')
, 'IMMEDIATE');
gv_payment_term_site :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'PAYMENT_TERM_SITE')
, 'IMMEDIATE');
gv_pay_dte_basis_lkp_code :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'PAY_DATE_BASIS_LOOKUP_CODE')
, 'DUE');
gv_pay_dte_basis_lkp_codesite :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'PAY_DATE_BASIS_LOOKUP_CODESITE')
, 'DUE');
gv_pay_group_lookup_code :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'PAY_GROUP_LOOKUP_CODE')
, 'EMPLOYEE');
gv_pay_group_lookup_code_site :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'PAY_GROUP_LOOKUP_CODE_SITE')
, 'EMPLOYEE');
gv_pay_site_flag :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'PAY_SITE_FLAG')
, 'Y');
gv_vendor_type_lookup_code :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'VENDOR_TYPE_LOOKUP_CODE')
, 'EMPLOYEE');
gv_remit_advice_del_method :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'REMIT_ADVICE_DEL_METHOD')
, 'EMAIL');
gv_le_value_set_name :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'LE_VALUE_SET_NAME')
-- , 'AFF LE');
--Arun Changed the NVL value to CDMS AFF LE
, 'CDMS AFF LE');
gv_wg_value_set_name :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'WG_VALUE_SET_NAME')
-- , 'AFF WG');
--Arun Changed the NVL value to CDMS AFF WG
, 'CDMS AFF WG');
gv_owg_value_set_name :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'OWG_VALUE_SET_NAME')
-- , 'AFF OWG');
--Arun Changed the NVL value to CDMS AFF OWG
, 'CDMS AFF OWG');
gv_intercompany_segment :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'INTERCOMPANY_SEGMENT')
, '000');
gv_future1_segment :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'FUTURE1_SEGMENT')
, '00000000');
gv_future2_segment :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'FUTURE2_SEGMENT')
, '00000000');

gv_flex_code :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'FLEX_CODE')
, 'GL#');
gv_flex_appl :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'FLEX_APPL')
, 'SQLGL');
gv_flex_structure_code :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'FLEX_STRUCTURE_CODE')
, 'CDM Smith Global AFF');
--Arun Changed the NVL value to CDMS GLOBAL AFF
--, 'CDMS Global AFF');
---------------------18-May-16 -----------------------
gv_intrim_ou_name :=
NVL (xxcdm_int_common_util_pkg.get_lookup_desc (
'XXCDM_AP_EMPSUP_EXT_DEFAULTS'
, 'INTRIM_OU_NAME')
, 'INTERIM OU');
---------------------18-May-16 -----------------------
debug (gn_statement
, 'initialize_global_variables (-)');
EXCEPTION
WHEN OTHERS
THEN
debug (gn_unexpected
, 'Error in initialize_global_variables: ' || SQLERRM);
RAISE;
END initialize_global_variables;

/**********************************************************************************
Name : submit_apxhrupd
Purpose : Procedure to sync Employee and Supplier records for name
updates
Input Parameters: pn_person_id NUMBER
Output Parameters:

***********************************************************************************
*/

PROCEDURE submit_apxhrupd (pn_person_id IN NUMBER DEFAULT NULL


, pd_record_date IN DATE DEFAULT NULL)
IS
CURSOR cur_sync_emp_supp
IS
SELECT ppf.business_group_id
, fnd_profile.VALUE ('gl_set_of_bks_id') ledger_id
FROM per_all_people_f ppf
, per_all_assignments_f paf
, per_periods_of_service pps
, per_business_groups pbg
, per_addresses pa
WHERE ppf.person_id = paf.person_id
AND paf.assignment_type = ('E')
AND ppf.business_group_id = pbg.business_group_id
AND paf.primary_flag = 'Y'
AND pa.person_id(+) = ppf.person_id
AND SYSDATE BETWEEN NVL (pa.date_from, SYSDATE)
AND NVL (pa.date_to, SYSDATE)
AND pps.person_id = ppf.person_id
AND pps.date_start = (SELECT MAX (pos2.date_start)
FROM per_periods_of_service pos2
WHERE pos2.person_id = pps.person_id
AND pos2.date_start <= TRUNC (SYSDATE))
AND TRUNC (NVL (pps.actual_termination_date -- final_process_date
--Changed by Saurabh on 24-Aug-16
, SYSDATE)) BETWEEN
ppf.effective_start_date
AND
ppf.effective_end_date
AND TRUNC (NVL (pps.actual_termination_date -- final_process_date
--Changed by Saurabh on 24-Aug-16
, SYSDATE)) BETWEEN
paf.effective_start_date
AND
paf.effective_end_date
AND ppf.person_id = NVL (pn_person_id, ppf.person_id)
AND ppf.employee_number IS NOT NULL
AND (ppf.last_update_date >= NVL (pd_record_date, gd_last_run_date)
OR paf.last_update_date >= NVL (pd_record_date, gd_last_run_date))
GROUP BY ppf.business_group_id
, fnd_profile.VALUE ('gl_set_of_bks_id');

ln_request_id NUMBER;
l_get_req_status_bln BOOLEAN := FALSE;
lv_request_phase_out VARCHAR2 (100);
lv_request_status_out VARCHAR2 (10);
lv_dev_request_phase_out VARCHAR2 (100);
lv_dev_request_status_out VARCHAR2 (10);
lv_request_status_msg_out VARCHAR2 (32000);
BEGIN
debug (gn_statement
, 'submit_apxhrupd (+)');
--------------------14-Mar-16 ------------------
fnd_global.apps_initialize (0
, gn_resp_id
, gn_resp_appl_id);

--------------------14-Mar-16 ------------------

FOR rec_sync_emp_supp IN cur_sync_emp_supp


LOOP
fnd_file.put_line(fnd_file.LOG,'Loop Started - rec_sync_emp_supp');
ln_request_id := -1;
debug (
gn_statement
, 'Submit request for apxhrupd with business group id '
|| rec_sync_emp_supp.business_group_id
|| ' and ledger id '
|| rec_sync_emp_supp.ledger_id);
ln_request_id :=
fnd_request.submit_request (
application => 'SQLAP'
, program => 'APXHRUPD'
, description => 'Employee Update Program ('
|| gv_business_process_name
|| ')'
, start_time => SYSDATE
, sub_request => FALSE
, argument1 => rec_sync_emp_supp.business_group_id
--, argument2 => rec_sync_emp_supp.ledger_id --Vivek
);
COMMIT;
debug (gn_statement
, 'Request id ' || ln_request_id);

fnd_file.put_line(fnd_file.LOG,'Request after - rec_sync_emp_supp');


IF NVL (ln_request_id, -1) > 0
THEN
WHILE NOT l_get_req_status_bln
LOOP
l_get_req_status_bln :=
fnd_concurrent.wait_for_request (ln_request_id --The request ID of the
program to wait on
, 0 --Time to wait between checks. This
is the number of seconds to sleep.
, 0 --The maximum time in seconds to
wait for the requests completion.
, lv_request_phase_out --The user
friendly request phase from FND_LOOKUPS.
, lv_request_status_out --The user
friendly request status from FND_LOOKUPS.
, lv_dev_request_phase_out --The request
phase as a constant string that can be used for program logic comparisons.
, lv_dev_request_status_out --The
request status as a constant string that can be used for program logic comparisons.
, lv_request_status_msg_out --The
completion message supplied if the request has completed.
);
COMMIT;
debug (gn_statement
, 'lv_request_phase_out : ' || lv_request_phase_out);
debug (gn_statement
, 'lv_request_status_out : ' || lv_request_status_out);
debug (gn_statement
, 'lv_dev_request_phase_out : ' || lv_dev_request_phase_out);
debug (gn_statement
, 'lv_dev_request_status_out : ' || lv_dev_request_status_out);
debug (gn_statement
, 'lv_request_status_msg_out : ' || lv_request_status_msg_out);
END LOOP;

IF l_get_req_status_bln
THEN
IF lv_request_phase_out != 'Completed'
OR lv_request_status_out IN ('Cancelled'
, 'Error'
, 'Terminated')
THEN
debug (gn_statement
, 'Error :Standard Employee Update Program failed');
END IF; --lv_request_phase_out
END IF; --l_get_req_status_bln
ELSE
debug (gn_statement
, 'Standard Employee Update Program submission failed ');
END IF;
END LOOP;

---------------14-Mar-16 ------------------
fnd_global.apps_initialize (gn_user_id
, gn_resp_id
, gn_resp_appl_id);
---------------14-Mar-16 ------------------
debug (gn_statement
, 'submit_apxhrupd (-)');
EXCEPTION
WHEN OTHERS
THEN
debug (gn_unexpected
, 'Error in submit_apxhrupd: ' || SQLERRM);
END submit_apxhrupd;

/**********************************************************************************
Name : create_vendor_site
Purpose : Procedure to create vendor site record
Input Parameters: p_vendor_site_rec -> Vendor Site record for which vendor site
will be created
Output Parameters:

***********************************************************************************
*/
PROCEDURE create_vendor_site (
p_vendor_site_rec IN ap_vendor_pub_pkg.r_vendor_site_rec_type
, pv_employee_number IN VARCHAR2
, pv_vendor_name IN VARCHAR2)
IS
l_vendor_site_rec ap_vendor_pub_pkg.r_vendor_site_rec_type;

lv_val_return_status VARCHAR2 (1) := NULL;


ln_val_msg_count NUMBER := NULL;
lv_val_msg_data VARCHAR2 (4000) := NULL;
ln_vendor_site_id NUMBER := NULL;
ln_vendor_id NUMBER := NULL;
ln_party_id NUMBER := NULL;
ln_party_site_id NUMBER := NULL;
ln_location_id NUMBER := NULL;
lv_debug_info VARCHAR2 (4000) := NULL;
BEGIN
debug (gn_statement
, 'create_vendor_site (+)');
l_vendor_site_rec := p_vendor_site_rec;
l_vendor_site_rec.vendor_site_code := 'HOME';
l_vendor_site_rec.party_site_id := ln_party_site_id;

debug (gn_statement
, 'ap_vendor_pub_pkg.create_vendor_site api call for HOME');
mo_global.set_policy_context ('S'
, l_vendor_site_rec.org_id);
ap_vendor_pub_pkg.create_vendor_site (
p_api_version => 1.0
, p_init_msg_list => fnd_api.g_true
, p_commit => fnd_api.g_false
, p_validation_level => fnd_api.g_valid_level_full
, x_return_status => lv_val_return_status
, x_msg_count => ln_val_msg_count
, x_msg_data => lv_val_msg_data
, p_vendor_site_rec => l_vendor_site_rec
, x_vendor_site_id => ln_vendor_site_id
, x_party_site_id => ln_party_site_id
, x_location_id => ln_location_id);

IF lv_val_return_status = fnd_api.g_ret_sts_success
THEN
debug (gn_statement
, 'Vendor HOME site record created successfully.');
----
l_vendor_site_rec := p_vendor_site_rec;
l_vendor_site_rec.vendor_site_code := 'OFFICE';
l_vendor_site_rec.location_id := ln_location_id;
l_vendor_site_rec.primary_pay_site_flag := 'Y';
lv_val_return_status := NULL;
ln_val_msg_count := NULL;
lv_val_msg_data := NULL;
ln_vendor_site_id := NULL;
ln_party_site_id := NULL;
ln_location_id := NULL;
l_vendor_site_rec.address_line1 := NULL;
l_vendor_site_rec.address_line2 := NULL;
l_vendor_site_rec.address_line3 := NULL;
l_vendor_site_rec.city := NULL;
l_vendor_site_rec.state := NULL;
l_vendor_site_rec.zip := NULL;
l_vendor_site_rec.province := NULL;
l_vendor_site_rec.county := NULL;
l_vendor_site_rec.country := NULL;
l_vendor_site_rec.address_style := NULL;

debug (gn_statement
, 'ap_vendor_pub_pkg.create_vendor_site api call for OFFICE');
mo_global.set_policy_context ('S'
, l_vendor_site_rec.org_id);
ap_vendor_pub_pkg.create_vendor_site (
p_api_version => 1.0
, p_init_msg_list => fnd_api.g_true
, p_commit => fnd_api.g_false
, p_validation_level => fnd_api.g_valid_level_full
, x_return_status => lv_val_return_status
, x_msg_count => ln_val_msg_count
, x_msg_data => lv_val_msg_data
, p_vendor_site_rec => l_vendor_site_rec
, x_vendor_site_id => ln_vendor_site_id
, x_party_site_id => ln_party_site_id
, x_location_id => ln_location_id);

IF lv_val_return_status = fnd_api.g_ret_sts_success
THEN
debug (gn_statement
, 'Vendor OFFICE site record created successfully.');
ELSE
debug (gn_statement
, 'Vendor OFFICE site record creation failed.');
gn_total_failseedval_records := gn_total_failseedval_records + 1;

IF (NVL (ln_val_msg_count, 0) > 1)


THEN
FOR i IN 1 .. ln_val_msg_count
LOOP
lv_debug_info :=
lv_debug_info
|| fnd_msg_pub.get (i
, p_encoded => fnd_api.g_false);
END LOOP;
ELSE
lv_debug_info := lv_val_msg_data;
END IF;

debug (gn_statement
, lv_debug_info);
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => pv_employee_number
, piv_business_process_id2 => pv_vendor_name
, piv_business_process_id3 => l_vendor_site_rec.vendor_site_code
, piv_business_process_step => 'Import Vendor Site Record'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_004'
, piv_error_column => NULL
, piv_error_value => NULL
, piv_error_description => lv_debug_info
, piv_error_type => 'Data Error');
END IF;
----
ELSE
debug (gn_statement
, 'Vendor HOME site record creation failed.');
gn_total_failseedval_records := gn_total_failseedval_records + 1;

IF (NVL (ln_val_msg_count, 0) > 1)


THEN
FOR i IN 1 .. ln_val_msg_count
LOOP
lv_debug_info :=
lv_debug_info
|| fnd_msg_pub.get (i
, p_encoded => fnd_api.g_false);
END LOOP;
ELSE
lv_debug_info := lv_val_msg_data;
END IF;

debug (gn_statement
, lv_debug_info);
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => pv_employee_number
, piv_business_process_id2 => pv_vendor_name
, piv_business_process_id3 => l_vendor_site_rec.vendor_site_code
, piv_business_process_step => 'Import Vendor Site Record'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_003'
, piv_error_column => NULL
, piv_error_value => NULL
, piv_error_description => lv_debug_info
, piv_error_type => 'Data Error');
END IF;

debug (gn_statement
, 'create_vendor_site (-)');
EXCEPTION
WHEN OTHERS
THEN
debug (gn_unexpected
, 'Error in create_vendor_site: ' || SQLERRM);
RAISE;
END create_vendor_site;

/**********************************************************************************
Name : update_external_payee
Purpose : Procedure to update external payee record
Input Parameters: p_vendor_site_rec -> Vendor Site record for which vendor site
will be updated
pv_employee_number VARCHAR2
pv_vendor_name VARCHAR2
pv_vendor_site_code VARCHAR2
Output Parameters: xv_ret_status VARCHAR2
xv_error_msg VARCHAR2

***********************************************************************************
*/
PROCEDURE update_external_payee (
p_external_payee_rec IN
iby_disbursement_setup_pub.external_payee_tab_type
, pv_employee_number IN VARCHAR2
, pv_vendor_name IN VARCHAR2
, pv_vendor_site_code IN VARCHAR2
, xv_ret_status OUT NOCOPY VARCHAR2
, xv_error_msg OUT NOCOPY VARCHAR2)
IS
--***
-- Local variable declarations
--***
lv_val_return_status VARCHAR2 (1000);
ln_val_msg_count NUMBER;
lv_val_msg_data VARCHAR2 (4000);
l_external_payee_rec iby_disbursement_setup_pub.external_payee_tab_type;
l_ext_payee_id_rec iby_disbursement_setup_pub.ext_payee_id_tab_type;
l_ext_payee_update_rec iby_disbursement_setup_pub.ext_payee_update_tab_type;
lv_debug_info VARCHAR2 (4000) := NULL;
ln_index_mess NUMBER;
lv_def_payment_method VARCHAR2(100) ; --added by Vibhor
BEGIN
debug (gn_statement
, 'update_external_payee (+)');
l_external_payee_rec := p_external_payee_rec;

debug (gn_statement
, 'Initialize external payee record variables');

BEGIN

SELECT NVL(ieppm.payment_method_code,iepa.default_payment_method_code) --added


by vibhor
INTO lv_def_payment_method
FROM iby_external_payees_all iepa,iby_ext_party_pmt_mthds ieppm
WHERE iepa.payee_party_id = l_external_payee_rec (1).payee_party_id
AND NVL (iepa.party_site_id, 0) = NVL (l_external_payee_rec
(1).payee_party_site_id, 0)
AND NVL (iepa.supplier_site_id, 0) = NVL (l_external_payee_rec
(1).supplier_site_id, 0)
AND NVL (iepa.org_id, 0) = NVL (l_external_payee_rec (1).payer_org_id, 0)
AND iepa.ext_payee_id = ieppm.ext_pmt_party_id
AND NVL(ieppm.inactive_date, SYSDATE+1) > SYSDATE
AND ieppm.primary_flag = 'Y';

EXCEPTION
WHEN OTHERS THEN
lv_def_payment_method := 'CHECK' ;

END;

SELECT ext_payee_id
, NVL (l_external_payee_rec (1).payee_party_id, payee_party_id)
, NVL (l_external_payee_rec (1).payment_function, payment_function)
, NVL (l_external_payee_rec (1).exclusive_pay_flag
, exclusive_payment_flag)
, NVL (l_external_payee_rec (1).payee_party_site_id, party_site_id)
, NVL (l_external_payee_rec (1).supplier_site_id, supplier_site_id)
, NVL (l_external_payee_rec (1).payer_org_id, org_id)
, NVL (l_external_payee_rec (1).payer_org_type, org_type)
, NVL (l_external_payee_rec (1).default_pmt_method
, lv_def_payment_method) --default_payment_method_code)
--commented by Vibhor
, NVL (l_external_payee_rec (1).ece_tp_loc_code
, ece_tp_location_code)
, NVL (l_external_payee_rec (1).bank_charge_bearer
, bank_charge_bearer)
, NVL (l_external_payee_rec (1).bank_instr1_code
, bank_instruction1_code)
, NVL (l_external_payee_rec (1).bank_instr2_code
, bank_instruction2_code)
, NVL (l_external_payee_rec (1).bank_instr_detail
, bank_instruction_details)
, NVL (l_external_payee_rec (1).pay_reason_code
, payment_reason_code)
, NVL (l_external_payee_rec (1).pay_reason_com
, payment_reason_comments)
, NVL (l_external_payee_rec (1).inactive_date, inactive_date)
, NVL (l_external_payee_rec (1).pay_message1, payment_text_message1)
, NVL (l_external_payee_rec (1).pay_message2, payment_text_message2)
, NVL (l_external_payee_rec (1).pay_message3, payment_text_message3)
, NVL (l_external_payee_rec (1).delivery_channel
, delivery_channel_code)
, NVL (l_external_payee_rec (1).pmt_format, payment_format_code)
, NVL (l_external_payee_rec (1).settlement_priority
, settlement_priority)
, NVL (l_external_payee_rec (1).remit_advice_delivery_method
, remit_advice_delivery_method)
, NVL (l_external_payee_rec (1).remit_advice_email
, remit_advice_email)
, NVL (l_external_payee_rec (1).edi_payment_format, NULL)
, NVL (l_external_payee_rec (1).edi_transaction_handling, NULL)
, NVL (l_external_payee_rec (1).edi_payment_method, NULL)
, NVL (l_external_payee_rec (1).edi_remittance_method, NULL)
, NVL (l_external_payee_rec (1).edi_remittance_instruction, NULL)
, NVL (l_external_payee_rec (1).remit_advice_fax, remit_advice_fax)
INTO l_ext_payee_id_rec (1).ext_payee_id
, l_external_payee_rec (1).payee_party_id
, l_external_payee_rec (1).payment_function
, l_external_payee_rec (1).exclusive_pay_flag
, l_external_payee_rec (1).payee_party_site_id
, l_external_payee_rec (1).supplier_site_id
, l_external_payee_rec (1).payer_org_id
, l_external_payee_rec (1).payer_org_type
, l_external_payee_rec (1).default_pmt_method
, l_external_payee_rec (1).ece_tp_loc_code
, l_external_payee_rec (1).bank_charge_bearer
, l_external_payee_rec (1).bank_instr1_code
, l_external_payee_rec (1).bank_instr2_code
, l_external_payee_rec (1).bank_instr_detail
, l_external_payee_rec (1).pay_reason_code
, l_external_payee_rec (1).pay_reason_com
, l_external_payee_rec (1).inactive_date
, l_external_payee_rec (1).pay_message1
, l_external_payee_rec (1).pay_message2
, l_external_payee_rec (1).pay_message3
, l_external_payee_rec (1).delivery_channel
, l_external_payee_rec (1).pmt_format
, l_external_payee_rec (1).settlement_priority
, l_external_payee_rec (1).remit_advice_delivery_method
, l_external_payee_rec (1).remit_advice_email
, l_external_payee_rec (1).edi_payment_format
, l_external_payee_rec (1).edi_transaction_handling
, l_external_payee_rec (1).edi_payment_method
, l_external_payee_rec (1).edi_remittance_method
, l_external_payee_rec (1).edi_remittance_instruction
, l_external_payee_rec (1).remit_advice_fax
FROM iby_external_payees_all
WHERE payee_party_id = l_external_payee_rec (1).payee_party_id
AND NVL (party_site_id, 0) =
NVL (l_external_payee_rec (1).payee_party_site_id, 0)
AND NVL (supplier_site_id, 0) =
NVL (l_external_payee_rec (1).supplier_site_id, 0)
AND NVL (org_id, 0) = NVL (l_external_payee_rec (1).payer_org_id, 0);

debug (
gn_statement
, 'l_external_payee_rec (1).payer_org_id '
|| l_external_payee_rec (1).payer_org_id);

IF l_external_payee_rec (1).payer_org_id IS NOT NULL


THEN
mo_global.set_policy_context ('S'
, l_external_payee_rec (1).payer_org_id);
END IF;

debug (gn_statement
, 'Call iby_disbursement_setup_pub.update_external_payee api');
iby_disbursement_setup_pub.update_external_payee (
p_api_version => 1.0
, p_init_msg_list => fnd_api.g_true
, p_ext_payee_tab => l_external_payee_rec
, p_ext_payee_id_tab => l_ext_payee_id_rec
, x_return_status => lv_val_return_status
, x_msg_count => ln_val_msg_count
, x_msg_data => lv_val_msg_data
, x_ext_payee_status_tab => l_ext_payee_update_rec);

debug (gn_statement
, 'x_msg_count ' || ln_val_msg_count);
debug (gn_statement
, 'x_return_status ' || lv_val_return_status);
debug (gn_statement
, 'x_msg_data ' || lv_val_msg_data);

IF lv_val_return_status = fnd_api.g_ret_sts_success
THEN
debug (gn_statement
, 'External Payee record updated successfully.');
ELSE
debug (gn_statement
, 'External Payee record update failed.');

gn_total_failseedval_records := gn_total_failseedval_records + 1;

IF (NVL (ln_val_msg_count, 0) > 1)


THEN
FOR i IN 1 .. ln_val_msg_count
LOOP
lv_debug_info :=
lv_debug_info
|| fnd_msg_pub.get (i
, p_encoded => fnd_api.g_false);
END LOOP;
ELSE
lv_debug_info := lv_val_msg_data;
END IF;

debug (gn_statement
, lv_debug_info);
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => pv_employee_number
, piv_business_process_id2 => pv_vendor_name
, piv_business_process_id3 => pv_vendor_site_code
, piv_business_process_step => 'Update External Payee Record'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_011'
, piv_error_column => NULL
, piv_error_value => NULL
, piv_error_description => lv_debug_info
, piv_error_type => 'Data Error');
END IF;

xv_ret_status := lv_val_return_status;
xv_error_msg := lv_debug_info;
debug (gn_statement
, 'update_external_payee (-)');
EXCEPTION
WHEN OTHERS
THEN
debug (gn_statement
, 'In Exception update_external_payee (-)');
xv_ret_status := 'E';
xv_error_msg := 'Error ocurred in update_external_payee ' || SQLERRM;
gn_total_failcustval_records := gn_total_failcustval_records + 1;
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => pv_employee_number
, piv_business_process_id2 => pv_vendor_name
, piv_business_process_id3 => pv_vendor_site_code
, piv_business_process_step => 'Update External Payee Record'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_012'
, piv_error_column => NULL
, piv_error_value => NULL
, piv_error_description => xv_error_msg
, piv_error_type => 'Data Error');
END update_external_payee;

/**********************************************************************************
Name : update_vendor_site
Purpose : Procedure to update vendor site record
Input Parameters: p_vendor_site_rec -> Vendor Site record for which vendor site
will be updated
Output Parameters:

***********************************************************************************
*/

PROCEDURE update_vendor_site (
p_vendor_site_rec IN ap_vendor_pub_pkg.r_vendor_site_rec_type
, pv_employee_number IN VARCHAR2
, pv_vendor_name IN VARCHAR2)
IS
--***
-- Local variable declarations
--***
l_vendor_site_rec ap_vendor_pub_pkg.r_vendor_site_rec_type;

lv_val_return_status VARCHAR2 (1) := NULL;


ln_val_msg_count NUMBER := NULL;
lv_val_msg_data VARCHAR2 (4000) := NULL;
ln_vendor_site_id NUMBER := NULL;
ln_vendor_id NUMBER := NULL;
ln_party_id NUMBER := NULL;
ln_party_site_id NUMBER := NULL;
ln_location_id NUMBER := NULL;
lv_debug_info VARCHAR2 (4000) := NULL;
l_external_payee_rec iby_disbursement_setup_pub.external_payee_tab_type;
l_ext_payee_id_rec iby_disbursement_setup_pub.ext_payee_id_tab_type;
skip_current_site EXCEPTION;
BEGIN
debug (gn_statement
, 'update_vendor_site (+)');
l_vendor_site_rec := p_vendor_site_rec;

BEGIN
l_external_payee_rec.delete;
l_ext_payee_id_rec.delete;

SELECT apss.vendor_site_id
, aps.party_id
, apss.party_site_id
, apss.org_id
INTO ln_vendor_site_id
, l_external_payee_rec (1).payee_party_id
, l_external_payee_rec (1).payee_party_site_id
, l_external_payee_rec (1).payer_org_id
FROM ap_supplier_sites_all apss
, ap_suppliers aps
WHERE apss.vendor_id = aps.vendor_id
AND apss.vendor_id = l_vendor_site_rec.vendor_id
AND apss.vendor_site_code = 'HOME'
AND apss.org_id = l_vendor_site_rec.org_id;

l_external_payee_rec (1).supplier_site_id := ln_vendor_site_id;


l_external_payee_rec (1).inactive_date :=
l_vendor_site_rec.inactive_date;
l_external_payee_rec (1).remit_advice_delivery_method := 'EMAIL';
l_external_payee_rec (1).remit_advice_email :=
l_vendor_site_rec.email_address;

update_external_payee (p_external_payee_rec => l_external_payee_rec


, pv_employee_number => pv_employee_number
, pv_vendor_name => pv_vendor_name
, pv_vendor_site_code => 'HOME'
, xv_ret_status => lv_val_return_status
, xv_error_msg => lv_debug_info);
debug (gn_statement
, 'xv_ret_status ' || lv_val_return_status);
debug (gn_statement
, 'xv_error_msg ' || lv_debug_info);
IF lv_val_return_status <> fnd_api.g_ret_sts_success
THEN
RAISE skip_current_site;
END IF;

lv_val_return_status := NULL;
lv_debug_info := NULL;
EXCEPTION
WHEN skip_current_site
THEN
RAISE skip_current_site;
WHEN OTHERS
THEN
ln_vendor_site_id := -1;
END;

IF ln_vendor_site_id <> -1
THEN
l_vendor_site_rec.vendor_site_id := ln_vendor_site_id;
mo_global.set_policy_context ('S'
, l_vendor_site_rec.org_id);

debug (gn_statement
, 'ap_vendor_pub_pkg.update_vendor_site api call for HOME');
ap_vendor_pub_pkg.update_vendor_site (
p_api_version => 1.0
, p_init_msg_list => fnd_api.g_true
, p_commit => fnd_api.g_false
, p_validation_level => fnd_api.g_valid_level_full
, x_return_status => lv_val_return_status
, x_msg_count => ln_val_msg_count
, x_msg_data => lv_val_msg_data
, p_vendor_site_rec => l_vendor_site_rec
, p_vendor_site_id => ln_vendor_site_id);

IF lv_val_return_status = fnd_api.g_ret_sts_success
THEN
debug (gn_statement
, 'Vendor HOME site record updated successfully.');

----
BEGIN
l_vendor_site_rec := p_vendor_site_rec;
l_external_payee_rec.delete;
l_ext_payee_id_rec.delete;

SELECT apss.vendor_site_id
, aps.party_id
, apss.party_site_id
, apss.org_id
INTO ln_vendor_site_id
, l_external_payee_rec (1).payee_party_id
, l_external_payee_rec (1).payee_party_site_id
, l_external_payee_rec (1).payer_org_id
FROM ap_supplier_sites_all apss
, ap_suppliers aps
WHERE apss.vendor_id = aps.vendor_id
AND apss.vendor_id = l_vendor_site_rec.vendor_id
AND apss.vendor_site_code = 'OFFICE'
AND apss.org_id = l_vendor_site_rec.org_id;

l_external_payee_rec (1).supplier_site_id := ln_vendor_site_id;


l_external_payee_rec (1).inactive_date :=
l_vendor_site_rec.inactive_date;
l_external_payee_rec (1).remit_advice_delivery_method := 'EMAIL';
l_external_payee_rec (1).remit_advice_email :=
l_vendor_site_rec.email_address;

update_external_payee (
p_external_payee_rec => l_external_payee_rec
, pv_employee_number => pv_employee_number
, pv_vendor_name => pv_vendor_name
, pv_vendor_site_code => 'OFFICE'
, xv_ret_status => lv_val_return_status
, xv_error_msg => lv_debug_info);
debug (gn_statement
, 'xv_ret_status ' || lv_val_return_status);
debug (gn_statement
, 'xv_error_msg ' || lv_debug_info);

IF lv_val_return_status <> fnd_api.g_ret_sts_success


THEN
RAISE skip_current_site;
END IF;

lv_val_return_status := NULL;
lv_debug_info := NULL;
EXCEPTION
WHEN skip_current_site
THEN
RAISE skip_current_site;
WHEN OTHERS
THEN
ln_vendor_site_id := -1;
END;

IF ln_vendor_site_id <> -1
THEN
l_vendor_site_rec.vendor_site_id := ln_vendor_site_id;
debug (gn_statement
, 'ap_vendor_pub_pkg.update_vendor_site api call for OFFICE');
ap_vendor_pub_pkg.update_vendor_site (
p_api_version => 1.0
, p_init_msg_list => fnd_api.g_true
, p_commit => fnd_api.g_false
, p_validation_level => fnd_api.g_valid_level_full
, x_return_status => lv_val_return_status
, x_msg_count => ln_val_msg_count
, x_msg_data => lv_val_msg_data
, p_vendor_site_rec => l_vendor_site_rec
, p_vendor_site_id => ln_vendor_site_id);

IF lv_val_return_status = fnd_api.g_ret_sts_success
THEN
debug (gn_statement
, 'Vendor OFFICE site record updated successfully.');
ELSE
debug (gn_statement
, 'Vendor OFFICE site record update failed.');
gn_total_failseedval_records := gn_total_failseedval_records + 1;

IF (NVL (ln_val_msg_count, 0) > 1)


THEN
FOR i IN 1 .. ln_val_msg_count
LOOP
lv_debug_info :=
lv_debug_info
|| fnd_msg_pub.get (i
, p_encoded => fnd_api.g_false);
END LOOP;
ELSE
lv_debug_info := lv_val_msg_data;
END IF;

debug (gn_statement
, lv_debug_info);
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => pv_employee_number
, piv_business_process_id2 => pv_vendor_name
, piv_business_process_id3 => l_vendor_site_rec.vendor_site_code
, piv_business_process_step => 'Update Vendor Site Record'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_006'
, piv_error_column => NULL
, piv_error_value => NULL
, piv_error_description => lv_debug_info
, piv_error_type => 'Data Error');
END IF;
ELSE
gn_total_failcustval_records := gn_total_failcustval_records + 1;
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => pv_employee_number
, piv_business_process_id2 => pv_vendor_name
, piv_business_process_id3 => l_vendor_site_rec.vendor_site_code
, piv_business_process_step => 'Update Vendor Site Record'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_007'
, piv_error_column => NULL
, piv_error_value => NULL
, piv_error_description => 'Vendor Site does not exist'
, piv_error_type => 'Data Error');
END IF; --ln_vendor_site_id <> -1
----
ELSE
debug (gn_statement
, 'Vendor HOME site record update failed.');
gn_total_failseedval_records := gn_total_failseedval_records + 1;

IF (NVL (ln_val_msg_count, 0) > 1)


THEN
FOR i IN 1 .. ln_val_msg_count
LOOP
lv_debug_info :=
lv_debug_info
|| fnd_msg_pub.get (i
, p_encoded => fnd_api.g_false);
END LOOP;
ELSE
lv_debug_info := lv_val_msg_data;
END IF;

debug (gn_statement
, lv_debug_info);

xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => pv_employee_number
, piv_business_process_id2 => pv_vendor_name
, piv_business_process_id3 => l_vendor_site_rec.vendor_site_code
, piv_business_process_step => 'Update Vendor Site Record'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_005'
, piv_error_column => NULL
, piv_error_value => NULL
, piv_error_description => lv_debug_info
, piv_error_type => 'Data Error');
END IF;
ELSE
gn_total_failcustval_records := gn_total_failcustval_records + 1;
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => pv_employee_number
, piv_business_process_id2 => pv_vendor_name
, piv_business_process_id3 => l_vendor_site_rec.vendor_site_code
, piv_business_process_step => 'Update Vendor Site Record'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_007'
, piv_error_column => NULL
, piv_error_value => NULL
, piv_error_description => 'Vendor Site does not exist'
, piv_error_type => 'Data Error');
END IF; --ln_vendor_site_id <> -1

debug (gn_statement
, 'update_vendor_site (-)');
EXCEPTION
WHEN skip_current_site
THEN
RETURN;
WHEN OTHERS
THEN
debug (gn_unexpected
, 'Error in update_vendor_site: ' || SQLERRM);
RAISE;
END update_vendor_site;

/**********************************************************************************
Name : change_vendor_site_ou
Purpose : Procedure to check and disable sites in other operating units
and create/update sites in current operating units
Input Parameters: p_vendor_site_rec -> Vendor Site record for which vendor site
will be updated
Output Parameters:
***********************************************************************************
*/

PROCEDURE change_vendor_site_ou (
p_vendor_site_rec IN ap_vendor_pub_pkg.r_vendor_site_rec_type
, pv_employee_number IN VARCHAR2
, pv_vendor_name IN VARCHAR2)
IS
--***
-- Local variable declarations
--***
l_vendor_site_rec ap_vendor_pub_pkg.r_vendor_site_rec_type;
lv_site_in_ou_flag VARCHAR2 (1) := 'Y';

CURSOR cur_inactivate_other_ou_sites (pn_vendor_id NUMBER


, pn_org_id NUMBER)
IS
SELECT org_id
FROM ap_supplier_sites_all
WHERE vendor_id = pn_vendor_id
AND inactive_date IS NULL
AND vendor_site_code IN ('HOME'
, 'OFFICE')
AND org_id <> pn_org_id
GROUP BY org_id;
BEGIN
debug (gn_statement
, 'change_vendor_site_ou (+)');

FOR rec_other_ou
IN cur_inactivate_other_ou_sites (p_vendor_site_rec.vendor_id
, p_vendor_site_rec.org_id)
LOOP
debug (gn_statement
, 'In disable Loop for org_id ' || rec_other_ou.org_id);
l_vendor_site_rec := NULL;
l_vendor_site_rec.org_id := rec_other_ou.org_id;
l_vendor_site_rec.vendor_id := p_vendor_site_rec.vendor_id;
l_vendor_site_rec.inactive_date := SYSDATE; -- + 21; --Changed by Saurabh on
18-May-16 --Changed by Saurabh on 25-Aug-16

debug (gn_statement
, 'Call update_vendor_site');
update_vendor_site (p_vendor_site_rec => l_vendor_site_rec
, pv_employee_number => pv_employee_number
, pv_vendor_name => pv_employee_number);
END LOOP;

BEGIN
SELECT 'Y'
INTO lv_site_in_ou_flag
FROM DUAL
WHERE EXISTS
(SELECT 1
FROM ap_supplier_sites_all
WHERE vendor_id = p_vendor_site_rec.vendor_id
AND vendor_site_code IN ('HOME'
, 'OFFICE')
AND org_id = p_vendor_site_rec.org_id);
EXCEPTION
WHEN OTHERS
THEN
lv_site_in_ou_flag := 'N';
END;

debug (
gn_statement
, 'Vendor site exist in '
|| p_vendor_site_rec.org_id
|| ' operating unit :'
|| lv_site_in_ou_flag);

IF lv_site_in_ou_flag = 'N'
THEN
debug (gn_statement
, 'Call create_vendor_site');
l_vendor_site_rec := p_vendor_site_rec;
create_vendor_site (p_vendor_site_rec => l_vendor_site_rec
, pv_employee_number => pv_employee_number
, pv_vendor_name => pv_employee_number);
ELSE
l_vendor_site_rec := p_vendor_site_rec;
l_vendor_site_rec.inactive_date :=
TO_DATE ('1'
, 'j');
debug (gn_statement
, 'Call update_vendor_site');
update_vendor_site (p_vendor_site_rec => l_vendor_site_rec
, pv_employee_number => pv_employee_number
, pv_vendor_name => pv_employee_number);
END IF;

debug (gn_statement
, 'change_vendor_site_ou (-)');
EXCEPTION
WHEN OTHERS
THEN
debug (gn_unexpected
, 'Error in change_vendor_site_ou: ' || SQLERRM);
RAISE;
END change_vendor_site_ou;

/**********************************************************************************
Name : process_vendor
Purpose : Procedure to create/update vendor record
Input Parameters:
Output Parameters:

***********************************************************************************
*/
PROCEDURE process_vendor (pn_person_id IN NUMBER DEFAULT NULL
, pd_record_date IN DATE DEFAULT NULL)
IS
l_vendor_rec ap_vendor_pub_pkg.r_vendor_rec_type;
l_vendor_site_rec ap_vendor_pub_pkg.r_vendor_site_rec_type;
lv_base_currency_code ap_system_parameters_all.base_currency_code%TYPE;
lv_payment_priority
ap_system_parameters_all.employee_payment_priority%TYPE;
ln_terms_id ap_terms.term_id%TYPE;

lv_val_return_status VARCHAR2 (1) := NULL;


lv_duplicate_vendor VARCHAR2 (1) := 'N';
ln_val_msg_count NUMBER := NULL;
lv_val_msg_data VARCHAR2 (4000) := NULL;
ln_vendor_id NUMBER := NULL;
ln_party_id NUMBER := NULL;
lv_supplier_num ap_suppliers.segment1%TYPE := NULL;
lv_vendor_name ap_suppliers.vendor_name%TYPE := NULL;
ld_end_date_active DATE := NULL;
ld_assign_date DATE;
ld_inactive_date DATE;
lv_debug_info VARCHAR2 (4000) := NULL;
ln_org_id NUMBER := 82;
ln_total_fail_old NUMBER := 0;
lv_operation VARCHAR2 (10) := 'CREATE';
lv_legal_entity VARCHAR2 (240) := NULL;
lv_workgroup VARCHAR2 (240) := NULL;
lv_organization_name VARCHAR2 (240) := NULL;
ln_liability_ccid NUMBER;
ln_prepay_ccid NUMBER;
derivation_exception EXCEPTION;
skip_international_employee EXCEPTION; --Added by Saurabh on 24-Aug-16
BEGIN
debug (gn_statement
, 'process_vendor (+)');
debug (gn_statement
, 'Set term id global variables');

SELECT term_id
INTO gn_payment_term_id
FROM ap_terms
WHERE name = gv_payment_term;

SELECT term_id
INTO gn_payment_term_site_id
FROM ap_terms
WHERE name = gv_payment_term_site;

FOR rec_emp_vendor IN cur_emp_vendor (pn_person_id


, pd_record_date)
LOOP
BEGIN
debug (
gn_statement
, 'Processing employee with employee number '
|| rec_emp_vendor.employee_number);
gn_total_records := gn_total_records + 1;
ln_total_fail_old :=
gn_total_failseedval_records + gn_total_failcustval_records;
lv_val_return_status := NULL;
ln_val_msg_count := NULL;
lv_val_msg_data := NULL;
ln_party_id := NULL;
l_vendor_rec := NULL;
l_vendor_site_rec := NULL;
ln_vendor_id := NULL;
lv_duplicate_vendor := gv_no;
lv_debug_info := NULL;
ld_assign_date := NULL;
ld_inactive_date := NULL;
lv_operation := gv_create_operation;

lv_organization_name := NULL;
lv_legal_entity := NULL;
lv_workgroup := NULL;
ln_org_id := NULL;
ln_liability_ccid := NULL;
ln_prepay_ccid := NULL;

--***
--Check for the vendor already exists in Oracle
--***
BEGIN
debug (gn_statement
, 'Check vendor record in the system');

SELECT vendor_id
, segment1
, vendor_name
, end_date_active
, gv_update_operation
INTO ln_vendor_id
, lv_supplier_num
, lv_vendor_name
, ld_end_date_active
, lv_operation
FROM ap_suppliers ap
WHERE ap.employee_id = rec_emp_vendor.person_id;

-------14-Mar-16 --------
gn_update_total_records := gn_update_total_records + 1;
-------14-Mar-16 --------
EXCEPTION
WHEN NO_DATA_FOUND
THEN
debug (
gn_statement
, 'Vendor for employee id '
|| rec_emp_vendor.person_id
|| ' is not found');
ln_vendor_id := -1;
lv_supplier_num := NULL;
lv_vendor_name := NULL;
ld_end_date_active := NULL;
lv_operation := gv_create_operation;
-------14-Mar-16 --------
gn_create_total_records := gn_create_total_records + 1;
-------14-Mar-16 --------
WHEN OTHERS
THEN
debug (gn_statement
, 'Duplicate vendor check failed with ' || SQLERRM);
ln_vendor_id := -1;
lv_supplier_num := NULL;
lv_vendor_name := NULL;
ld_end_date_active := NULL;
lv_operation := gv_create_operation;
-------14-Mar-16 --------
gn_create_total_records := gn_create_total_records + 1;
-------14-Mar-16 --------
END;

l_vendor_rec.enabled_flag := gv_enabled_flag;
l_vendor_rec.employee_id := rec_emp_vendor.person_id;
l_vendor_rec.vendor_type_lookup_code := gv_vendor_type_lookup_code;
l_vendor_rec.one_time_flag := 'N';
l_vendor_rec.terms_id := gn_payment_term_id;
l_vendor_rec.pay_date_basis_lookup_code := gv_pay_dte_basis_lkp_code;
l_vendor_rec.pay_group_lookup_code := gv_pay_group_lookup_code;
l_vendor_rec.payment_priority := gv_payment_priority;
l_vendor_rec.match_option := gv_match_option;

l_vendor_rec.invoice_currency_code := lv_base_currency_code;
l_vendor_rec.payment_currency_code := lv_base_currency_code;

l_vendor_rec.vendor_name := rec_emp_vendor.vendor_name;

l_vendor_rec.party_id := rec_emp_vendor.party_id;
l_vendor_rec.ext_payee_rec.default_pmt_method :=
NVL (rec_emp_vendor.emp_payment_mthod
, gv_payment_method_lookup_code);
l_vendor_site_rec.ext_payee_rec.remit_advice_delivery_method :=
gv_remit_advice_del_method;
l_vendor_site_rec.ext_payee_rec.remit_advice_email :=
rec_emp_vendor.email_address;

debug (gn_statement
, 'Call get_le_wg_details ');
get_le_wg_details (
pn_organization_id => rec_emp_vendor.organization_id
, xv_organization_name => lv_organization_name
, xv_legal_entity => lv_legal_entity
, xv_workgroup => lv_workgroup);

--Added by Saurabh on 24-Aug-16


debug (gn_statement
, 'Checking for international organization ');

IF check_org_exclusion (lv_organization_name)
THEN
debug (
gn_statement
, lv_organization_name
|| ' is an international organization, processing will be skipped ');
RAISE skip_international_employee;
END IF;

--Added by Saurabh on 24-Aug-16


IF lv_legal_entity IS NULL
OR lv_workgroup IS NULL
THEN
gn_total_failcustval_records := gn_total_failcustval_records + 1;

-----14-Mar-16 ----
IF lv_operation = gv_create_operation
THEN
gn_create_failcustval_records := gn_create_failcustval_records + 1;
ELSE
gn_update_failcustval_records := gn_update_failcustval_records + 1;
END IF;

-----14-Mar-16 ----
debug (
gn_statement
, 'Organization on employee assignment does not have legal entity and
workgroup information.');
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => rec_emp_vendor.employee_number
, piv_business_process_id2 => rec_emp_vendor.vendor_name
, piv_business_process_id3 => NULL --vendor_site_code
, piv_business_process_step => 'Legal entity and workgroup derivation'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_008'
, piv_error_column => 'ORGANIZATION_NAME'
, piv_error_value => lv_organization_name
, piv_error_description => 'Organization on employee assignment
does not have legal entity and workgroup information.'
, piv_error_type => 'Data Error');
RAISE derivation_exception;
ELSE
ln_org_id := get_org_id (lv_legal_entity);

IF ln_org_id IS NULL
THEN
gn_total_failcustval_records := gn_total_failcustval_records + 1;

-----14-Mar-16 ----
IF lv_operation = gv_create_operation
THEN
gn_create_failcustval_records :=
gn_create_failcustval_records + 1;
ELSE
gn_update_failcustval_records :=
gn_update_failcustval_records + 1;
END IF;

-----14-Mar-16 ----
debug (gn_statement
, 'Operating Unit can not be derived for Legal Entity.');
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => rec_emp_vendor.employee_number
, piv_business_process_id2 => rec_emp_vendor.vendor_name
, piv_business_process_id3 => NULL --vendor_site_code
, piv_business_process_step => 'Operating Unit derivation'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_009'
, piv_error_column => 'LEGAL_ENTITY'
, piv_error_value => lv_legal_entity
, piv_error_description => 'Operating Unit can not be derived for
Legal Entity.'
, piv_error_type => 'Data Error');
RAISE derivation_exception;
-----------18-May-16 ----------
ELSIF ln_org_id = -1
THEN
gn_total_failcustval_records := gn_total_failcustval_records + 1;

-----14-Mar-16 ----
IF lv_operation = gv_create_operation
THEN
gn_create_failcustval_records :=
gn_create_failcustval_records + 1;
ELSE
gn_update_failcustval_records :=
gn_update_failcustval_records + 1;
END IF;

-----14-Mar-16 ----
debug (
gn_statement
, 'Employee with employee number '
|| rec_emp_vendor.employee_number
|| ' is an international employee, supplier details will not be
created.');
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => rec_emp_vendor.employee_number
, piv_business_process_id2 => rec_emp_vendor.vendor_name
, piv_business_process_id3 => NULL --vendor_site_code
, piv_business_process_step => 'International Employee
Identification'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_009.1'
, piv_error_column => 'LEGAL_ENTITY'
, piv_error_value => lv_legal_entity
, piv_error_description => 'Employee is an international
employee, supplier details will not be created.'
, piv_error_type => 'Data Error');
RAISE derivation_exception;
-----------18-May-16 ----------
ELSE
IF NOT check_segment (
pv_flex_value_set_name => gv_le_value_set_name
, pv_flex_value => lv_legal_entity)
THEN
gn_total_failcustval_records := gn_total_failcustval_records + 1;

-----14-Mar-16 ----
IF lv_operation = gv_create_operation
THEN
gn_create_failcustval_records :=
gn_create_failcustval_records + 1;
ELSE
gn_update_failcustval_records :=
gn_update_failcustval_records + 1;
END IF;

-----14-Mar-16 ----
debug (gn_statement
, 'Legal Entity segment is not valid');
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => rec_emp_vendor.employee_number
, piv_business_process_id2 => rec_emp_vendor.vendor_name
, piv_business_process_id3 => NULL --vendor_site_code
, piv_business_process_step => 'Legal Entity segment validation'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_013'
, piv_error_column => 'LEGAL_ENTITY'
, piv_error_value => lv_legal_entity
, piv_error_description => 'Legal Entity segment is not valid.'
, piv_error_type => 'Data Error');
RAISE derivation_exception;
END IF;

IF NOT check_segment (
pv_flex_value_set_name => gv_wg_value_set_name
, pv_flex_value => lv_workgroup)
THEN
gn_total_failcustval_records := gn_total_failcustval_records + 1;

-----14-Mar-16 ----
IF lv_operation = gv_create_operation
THEN
gn_create_failcustval_records :=
gn_create_failcustval_records + 1;
ELSE
gn_update_failcustval_records :=
gn_update_failcustval_records + 1;
END IF;

-----14-Mar-16 ----
debug (gn_statement
, 'Workgroup segment is not valid');
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => rec_emp_vendor.employee_number
, piv_business_process_id2 => rec_emp_vendor.vendor_name
, piv_business_process_id3 => NULL --vendor_site_code
, piv_business_process_step => 'Workgroup segment validation'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_014'
, piv_error_column => 'WORKGROUP'
, piv_error_value => lv_workgroup
, piv_error_description => 'Workgroup segment is not valid.'
, piv_error_type => 'Data Error');
RAISE derivation_exception;
END IF;

IF NOT check_segment (
pv_flex_value_set_name => gv_owg_value_set_name
, pv_flex_value => lv_workgroup)
THEN
gn_total_failcustval_records := gn_total_failcustval_records + 1;

-----14-Mar-16 ----
IF lv_operation = gv_create_operation
THEN
gn_create_failcustval_records :=
gn_create_failcustval_records + 1;
ELSE
gn_update_failcustval_records :=
gn_update_failcustval_records + 1;
END IF;

-----14-Mar-16 ----
debug (gn_statement
, 'Owning Workgroup segment is not valid');
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => rec_emp_vendor.employee_number
, piv_business_process_id2 => rec_emp_vendor.vendor_name
, piv_business_process_id3 => NULL --vendor_site_code
, piv_business_process_step => 'Owning Workgroup segment
validation'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_015'
, piv_error_column => 'OWNING_WORKGROUP'
, piv_error_value => lv_workgroup
, piv_error_description => 'Owning Workgroup segment is not
valid.'
, piv_error_type => 'Data Error');
RAISE derivation_exception;
END IF;

get_code_combinations (pv_legal_entity => lv_legal_entity


, pv_workgroup => lv_workgroup
, pn_org_id => ln_org_id
, xn_liability_ccid => ln_liability_ccid
, xn_prepay_ccid => ln_prepay_ccid
, xv_error_message => lv_val_msg_data);

IF NVL (ln_liability_ccid, 0) = 0
OR NVL (ln_prepay_ccid, 0) = 0
THEN
gn_total_failcustval_records := gn_total_failcustval_records + 1;

-----14-Mar-16 ----
IF lv_operation = gv_create_operation
THEN
gn_create_failcustval_records :=
gn_create_failcustval_records + 1;
ELSE
gn_update_failcustval_records :=
gn_update_failcustval_records + 1;
END IF;

-----14-Mar-16 ----
debug (gn_statement
, 'Code Combinations can not be derived.');
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => rec_emp_vendor.employee_number
, piv_business_process_id2 => rec_emp_vendor.vendor_name
, piv_business_process_id3 => NULL --vendor_site_code
, piv_business_process_step => 'Code combination derivation'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_010'
, piv_error_column => 'LEGAL_ENTITY'
, piv_error_value => lv_legal_entity
, piv_error_description => lv_val_msg_data
, piv_error_type => 'Data Error');
RAISE derivation_exception;
END IF;
END IF;
END IF;

BEGIN
debug (gn_statement
, 'Get currency from operating unit''s ledger');

SELECT gl.currency_code
, NULL
INTO lv_base_currency_code
, lv_payment_priority
FROM hr_operating_units hou
, gl_ledgers gl
WHERE gl.ledger_id = hou.set_of_books_id
AND hou.organization_id = ln_org_id;
END;

l_vendor_site_rec.org_id := ln_org_id;

l_vendor_site_rec.pay_site_flag := gv_pay_site_flag;
l_vendor_site_rec.terms_id := gn_payment_term_site_id;
l_vendor_site_rec.pay_date_basis_lookup_code :=
gv_pay_dte_basis_lkp_codesite;
l_vendor_site_rec.pay_group_lookup_code :=
gv_pay_group_lookup_code_site;
l_vendor_site_rec.payment_priority := gv_payment_priority_site;

l_vendor_site_rec.invoice_currency_code := lv_base_currency_code;
l_vendor_site_rec.payment_currency_code := lv_base_currency_code;
l_vendor_site_rec.ext_payee_rec.default_pmt_method :=
NVL (rec_emp_vendor.emp_payment_mthod
, gv_payment_method_lookup_code);
l_vendor_site_rec.accts_pay_code_combination_id := ln_liability_ccid;
l_vendor_site_rec.prepay_code_combination_id := ln_prepay_ccid;
l_vendor_site_rec.ext_payee_rec.remit_advice_delivery_method :=
gv_remit_advice_del_method;
l_vendor_site_rec.supplier_notif_method := gv_remit_advice_del_method;
l_vendor_site_rec.remit_advice_delivery_method :=
gv_remit_advice_del_method;
l_vendor_site_rec.ext_payee_rec.remit_advice_email :=
rec_emp_vendor.email_address;
l_vendor_site_rec.email_address := rec_emp_vendor.email_address;
l_vendor_site_rec.remittance_email := rec_emp_vendor.email_address;

IF rec_emp_vendor.address_id IS NULL
THEN
gn_total_failcustval_records := gn_total_failcustval_records + 1;

-----14-Mar-16 ----
IF lv_operation = gv_create_operation
THEN
gn_create_failcustval_records := gn_create_failcustval_records + 1;
ELSE
gn_update_failcustval_records := gn_update_failcustval_records + 1;
END IF;
-----14-Mar-16 ----
debug (gn_statement
, 'Address for person does not exist in the system.');

xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => rec_emp_vendor.employee_number
, piv_business_process_id2 => rec_emp_vendor.vendor_name
, piv_business_process_id3 => NULL --vendor_site_code
, piv_business_process_step => 'Employee address validation'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_002'
, piv_error_column => 'ADDRESS_ID'
, piv_error_value => NULL
, piv_error_description => 'Address for person does not exist in
the system.'
, piv_error_type => 'Data Error');
ELSE
IF lv_operation = gv_create_operation
THEN
debug (gn_statement
, 'Call ap_vendor_pub_pkg.create_vendor api');
ap_vendor_pub_pkg.create_vendor (
p_api_version => 1.0
, p_init_msg_list => fnd_api.g_true
, p_commit => fnd_api.g_false
, p_validation_level => fnd_api.g_valid_level_full
, x_return_status => lv_val_return_status
, x_msg_count => ln_val_msg_count
, x_msg_data => lv_val_msg_data
, p_vendor_rec => l_vendor_rec
, x_vendor_id => ln_vendor_id
, x_party_id => ln_party_id);
ELSE
IF rec_emp_vendor.inactive_date IS NOT NULL
THEN
ld_inactive_date := rec_emp_vendor.inactive_date + 21; --3 Weeks from
date of termination
ELSE
IF ld_end_date_active IS NOT NULL
THEN
ld_inactive_date :=
TO_DATE ('1'
, 'j');
ELSE
ld_inactive_date := NULL;
END IF;
END IF;

debug (gn_statement
, 'ld_inactive_date ' || ld_inactive_date);

--Inactivate vendor sites first--


IF ld_inactive_date IS NOT NULL
THEN
l_vendor_site_rec := NULL;
l_vendor_site_rec.org_id := ln_org_id;
l_vendor_site_rec.vendor_id := ln_vendor_id;
l_vendor_site_rec.inactive_date := ld_inactive_date;
debug (gn_statement
, 'Update vendor site when ld_inactive_date is not null');
debug (gn_statement
, 'Call update_vendor_site');
update_vendor_site (
p_vendor_site_rec => l_vendor_site_rec
, pv_employee_number => rec_emp_vendor.employee_number
, pv_vendor_name => rec_emp_vendor.vendor_name);
debug (gn_statement
, 'Update vendor when ld_inactive_date is not null');
l_vendor_rec.end_date_active := ld_inactive_date;
debug (gn_statement
, 'Call ap_vendor_pub_pkg.update_vendor api');
ap_vendor_pub_pkg.update_vendor (
p_api_version => 1.0
, p_init_msg_list => fnd_api.g_true
, p_commit => fnd_api.g_false
, p_validation_level => fnd_api.g_valid_level_full
, x_return_status => lv_val_return_status
, x_msg_count => ln_val_msg_count
, x_msg_data => lv_val_msg_data
, p_vendor_rec => l_vendor_rec
, p_vendor_id => ln_vendor_id);
ELSE
l_vendor_rec.end_date_active := ld_inactive_date;
debug (gn_statement
, 'Update vendor when ld_inactive_date is null');
debug (gn_statement
, 'Call ap_vendor_pub_pkg.update_vendor api');
-- ap_vendor_pub_pkg.update_vendor (
-- p_api_version => 1.0
-- , p_init_msg_list => fnd_api.g_true
-- , p_commit => fnd_api.g_false
-- , p_validation_level => fnd_api.g_valid_level_full
-- , x_return_status => lv_val_return_status
-- , x_msg_count => ln_val_msg_count
-- , x_msg_data => lv_val_msg_data
-- , p_vendor_rec => l_vendor_rec
-- , p_vendor_id => ln_vendor_id);
END IF;
END IF; --ln_vendor_id = -1

IF lv_val_return_status = fnd_api.g_ret_sts_success
THEN
debug (
gn_statement
, 'Vendor record created/updated successfully.'
|| l_vendor_rec.end_date_active);
---------for vendor site creation--------
l_vendor_site_rec.vendor_id := ln_vendor_id;

---------for vendor site creation--------


IF lv_operation = gv_create_operation
THEN
debug (gn_statement
, 'Call create_vendor_site');
create_vendor_site (
p_vendor_site_rec => l_vendor_site_rec
, pv_employee_number => rec_emp_vendor.employee_number
, pv_vendor_name => rec_emp_vendor.vendor_name);
ELSIF ld_inactive_date IS NULL
THEN
l_vendor_site_rec.org_id := ln_org_id;
l_vendor_site_rec.vendor_id := ln_vendor_id;
l_vendor_site_rec.inactive_date := ld_inactive_date;
debug (
gn_statement
, 'Checking vendor sites in operating units when ld_inactive_date is
null');
debug (gn_statement
, 'Call change_vendor_site_ou');
change_vendor_site_ou (
p_vendor_site_rec => l_vendor_site_rec
, pv_employee_number => rec_emp_vendor.employee_number
, pv_vendor_name => rec_emp_vendor.vendor_name);
END IF;
ELSE
debug (gn_statement
, 'Vendor record creation/update failed.');
gn_total_failseedval_records := gn_total_failseedval_records + 1;

IF (NVL (ln_val_msg_count, 0) > 1)


THEN
FOR i IN 1 .. ln_val_msg_count
LOOP
lv_debug_info :=
lv_debug_info
|| fnd_msg_pub.get (i
, p_encoded => fnd_api.g_false);
END LOOP;
ELSE
lv_debug_info := lv_val_msg_data;
END IF; -- (NVL (ln_val_msg_count, 0) > 1)

debug (gn_statement
, lv_debug_info);

xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => rec_emp_vendor.employee_number
, piv_business_process_id2 => rec_emp_vendor.vendor_name
, piv_business_process_id3 => NULL --vendor_site_code
, piv_business_process_step => 'Import Vendor Record'
, piv_system_name => 'EBS'
, piv_error_code => 'XXCDM_AP_EMPSUP_EXT_001'
, piv_error_column => NULL
, piv_error_value => NULL
, piv_error_description => lv_debug_info
, piv_error_type => 'Data Error');
END IF; --lv_val_return_status = fnd_api.g_ret_sts_success

IF gn_total_failseedval_records + gn_total_failcustval_records >


ln_total_fail_old
THEN
----14-Mar-16 ----
IF lv_operation = gv_create_operation
THEN
IF gn_total_failseedval_records >
gn_create_failseedval_records
+ gn_update_failseedval_records
THEN
gn_create_failseedval_records :=
gn_create_failseedval_records + 1;
ELSE
gn_create_failcustval_records :=
gn_create_failcustval_records + 1;
END IF;
ELSE
IF gn_total_failseedval_records >
gn_create_failseedval_records
+ gn_update_failseedval_records
THEN
gn_update_failseedval_records :=
gn_update_failseedval_records + 1;
ELSE
gn_update_failcustval_records :=
gn_update_failcustval_records + 1;
END IF;
END IF;

----14-Mar-16 ----
ROLLBACK;
ELSE
COMMIT;
gn_total_processed_records := gn_total_processed_records + 1;

----14-Mar-16 ----
IF lv_operation = gv_create_operation
THEN
gn_create_processed_records := gn_create_processed_records + 1;
----24-Aug-16 ----
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => rec_emp_vendor.employee_number
, piv_business_process_id2 => rec_emp_vendor.vendor_name
, piv_business_process_id3 => NULL --vendor_site_code
, piv_business_process_step => 'Create'
, piv_system_name => 'EBS'
, piv_error_code => 'SUCCESS'
, piv_error_column => NULL
, piv_error_value => NULL
, piv_error_description => 'Supplier details created
successfully.'
, piv_error_type => 'No Error');
----24-Aug-16 ----
ELSE
gn_update_processed_records := gn_update_processed_records + 1;
----24-Aug-16 ----
xxcdm_int_common_util_pkg.capture_error (
piv_business_process_id1 => rec_emp_vendor.employee_number
, piv_business_process_id2 => rec_emp_vendor.vendor_name
, piv_business_process_id3 => NULL --vendor_site_code
, piv_business_process_step => 'Update'
, piv_system_name => 'EBS'
, piv_error_code => 'SUCCESS'
, piv_error_column => NULL
, piv_error_value => NULL
, piv_error_description => 'Supplier details updated
successfully.'
, piv_error_type => 'No Error');
----24-Aug-16 ----
END IF;
----14-Mar-16 ----
END IF; --gn_total_failseedval_records > ln_total_fail_old
END IF; --rec_emp_vendor.address_id IS NULL
EXCEPTION
--Added by Saurabh on 24-Aug-16
WHEN skip_international_employee
THEN
gn_total_records := gn_total_records - 1;
gn_total_skipped_records := gn_total_skipped_records + 1;

IF lv_operation = gv_create_operation
THEN
gn_create_total_records := gn_create_total_records - 1;
ELSE
gn_update_total_records := gn_update_total_records - 1;
END IF;

CONTINUE;
--Added by Saurabh on 24-Aug-16
WHEN derivation_exception
THEN
CONTINUE;
WHEN OTHERS
THEN
RAISE;
END;
END LOOP; --rec_emp_vendor loop

debug (gn_statement
, 'process_vendor (-)');
EXCEPTION
WHEN OTHERS
THEN
debug (gn_unexpected
, 'Error in process_vendor: ' || SQLERRM);
RAISE;
END process_vendor;

/*************************************************************************
*
* PROCEDURE: main
*
* DESCRIPTION: Main procedure which will be called by concurrent
* program and will execute other procedures and functions
* Input Parameters: pn_person_id NUMBER -> Employee id to processed
* pv_record_date VARCHAR2 -> Employee record date
* Output Parameters: pv_errbuf and pv_retcode used by standard concurrent
program
*************************************************************************/
PROCEDURE main (xv_errbuf OUT NOCOPY VARCHAR2
, xn_retcode OUT NOCOPY NUMBER
, pn_person_id IN NUMBER DEFAULT NULL
, pv_record_date IN VARCHAR2 DEFAULT NULL)
IS
lv_batch_status VARCHAR2 (1) := 'S';
ld_record_date DATE := NULL;
BEGIN
debug (gn_statement
, 'main (+)');
debug (
gn_statement
, 'Initialize error framework batch summary by calling
xxcdm_int_common_util_pkg.initialize');
xxcdm_int_common_util_pkg.initialize (
piv_batch_key => 'PROC-EXT-001_'
|| TO_CHAR (SYSDATE
, 'MMDDRRRRHH24MISS')
, piv_business_process_name => gv_business_process_name
, piv_business_process_entity => gv_business_process_entity
, piv_business_process_domain => gv_business_process_domain
, piv_data_file_name => 'N/A'
, piv_source => gv_source
, pin_total_no_records => 0
, piv_notif_email_id => NULL);
get_last_run_date_time;
ld_record_date :=
NVL (fnd_date.canonical_to_date (pv_record_date), gd_last_run_date);
output ('Record Date :' || ld_record_date);
debug (gn_statement
, 'Start Processing Employee Records');
initialize_global_variables;
submit_apxhrupd (pn_person_id
, ld_record_date);
process_vendor (pn_person_id
, ld_record_date);
xxcdm_int_common_util_pkg.publish_errors;

IF gn_total_failseedval_records + gn_total_failcustval_records > 0


THEN
lv_batch_status := gv_error_status;
ELSE
lv_batch_status := gv_success_status;
END IF;

debug (gn_statement
, 'End Processing Employee Records');
debug (
gn_statement
, 'Update error framework batch summary by calling
xxcdm_int_common_util_pkg.update_summary_record');
xxcdm_int_common_util_pkg.update_summary_record (
pin_total_no_records => gn_total_records
, pin_total_processed_records => gn_total_processed_records
, pin_total_failcustval_records => gn_total_failcustval_records
, pin_total_failseedval_records => gn_total_failseedval_records
, piv_batch_status => lv_batch_status);
debug (
gn_statement
, 'Generate summary output by calling
xxcdm_int_common_util_pkg.generate_summary_output');
xxcdm_int_common_util_pkg.generate_summary_output;
-----------------14-Mar-16 ---------------------------
output (
'=====================================================================');
output (
'Total no. of Create Records: '
|| gn_create_total_records);
output (
'Number of Create Records Processed: '
|| gn_create_processed_records);
output (
'Number of Create Records Failed in Custom Validations: '
|| gn_create_failcustval_records);
output (
'Number of Create Records Failed in Standard Validations: '
|| gn_create_failseedval_records);

output (
'=====================================================================');

output (
'=====================================================================');
output (
'Total no. of Update Records: '
|| gn_update_total_records);
output (
'Number of Update Records Processed: '
|| gn_update_processed_records);
output (
'Number of Update Records Failed in Custom Validations: '
|| gn_update_failcustval_records);
output (
'Number of Update Records Failed in Standard Validations: '
|| gn_update_failseedval_records);

output (
'=====================================================================');

-----------------14-Mar-16 ---------------------------
-----------------24-Aug-16 ---------------------------
output (
'=====================================================================');
output (
'Total no. of Records which got skipped: '
|| gn_total_skipped_records);
output (
'=====================================================================');

-----------------24-Aug-16 ---------------------------
IF gn_total_records > 0 --gn_total_failseedval_records +
gn_total_failcustval_records > 0 --changed by Saurabh on 24-Aug-16
THEN
debug (
gn_statement
, 'Submit error report by calling
xxcdm_int_common_util_pkg.submit_error_report');
xxcdm_int_common_util_pkg.submit_error_report;
END IF;

debug (gn_statement
, 'main (-)');
EXCEPTION
WHEN OTHERS
THEN
xn_retcode := 2;
xv_errbuf :=
TO_CHAR (
'UNEXPECTED ERROR, with call stack '
|| DBMS_UTILITY.format_call_stack
|| 'with error stack '
|| DBMS_UTILITY.format_error_stack
|| 'with error backtrace '
|| DBMS_UTILITY.format_error_backtrace);
debug (
gn_unexpected
, TO_CHAR (
'UNEXPECTED ERROR, with call stack '
|| DBMS_UTILITY.format_call_stack
|| 'with error stack '
|| DBMS_UTILITY.format_error_stack
|| 'with error backtrace '
|| DBMS_UTILITY.format_error_backtrace));
END main;
END xxcdm_ap_empsup_ext_pkg;
/

You might also like