select papf.
PERSON_NUMBER
,pp.attribute1 as SAGE_EMP_CODE
,rpad(pni.national_identifier_number,20) as ID_NUMBER
,ppass.passport_number as PASSPORT_NUMBER
,per_extract_utility.get_decoded_lookup('PER_ETHNICITY', pe.ethnicity) as
ETHNICITY
,nvl(pplf.per_information1, pplf.attribute4) as FOREIGN_NATIONAL
----- ,pplf.attribute4 as FOREIGN_NATIONAL_MZ
,rpad(pplf.attribute1,20) as INCOME_TAX
,per_extract_utility.get_decoded_lookup('PER_HIGHEST_EDUCATION_LEVEL',pplf.hi
ghest_education_level) as HIGHEST_EDUCATION_LEVEL
,per_extract_utility.get_decoded_lookup('DISABILITY_CATEGORY', pdf.category)
as DISABLITY
,pdf.accommodation_request as DISABLITY_ACCOMMODATION_REQUEST
,pdf.effective_start_date as DISABLITY_START_DATE
,per_extract_utility.get_decoded_lookup('TITLE', ppnf.title) as TITLE
,ppnf.first_name
,ppnf.middle_names
,ppnf.last_name
,ppnf.previous_last_name as MAIDEN_NAME
,ppnf.known_as
,ppnf.nam_information1 as INITIALS
----- ,ppnf.nam_information15 as MZ_INITIALS
,hr_general.decode_lookup('SEX', pplf.sex) as GENDER
,per_extract_utility.get_decoded_lookup('MAR_STATUS', pplf.marital_status) as
MARITAL_STATUS
,hr_general.decode_lookup('NATIONALITY', pc.legislation_code) as CITZENSHIP
,pp.date_of_birth as DATE_OF_BIRTH
,(select pea.email_address
from per_email_addresses pea
where 1=1
and :p_date between nvl(pea.date_from, :p_date) and
nvl(pea.date_to, :p_date)
and pea.email_type = 'W1'
---and papf.primary_email_id = pea.email_address_id
and pea.person_id = papf.person_id
and rownum=1) as WORK_EMAIL
,(select pea.email_address
from per_email_addresses pea
where 1=1
and :p_date between nvl(pea.date_from, :p_date) and
nvl(pea.date_to, :p_date)
and pea.email_type = 'H1'
---and papf.primary_email_id = pea.email_address_id
and pea.person_id = papf.person_id
and rownum=1) as PRIVATE_EMAIL
,(select listagg(rpad(pphone.phone_number,20), ',') within group (order by
pphone.person_id)
from per_phones pphone
where 1=1
and (pphone.date_to is null or :p_date between pphone.date_from and
pphone.date_to)
and pphone.phone_type in ('WM','W1')
and pphone.person_id = papf.person_id
and rownum=1) as WORK_PHONE_NUMBER
,(select listagg(rpad(pphone.phone_number,20), ',') within group (order by
pphone.person_id)
from per_phones pphone
where 1=1
and (pphone.date_to is null or :p_date between pphone.date_from and
pphone.date_to)
and pphone.phone_type in ('HM','H1')
and pphone.person_id = papf.person_id
and rownum=1) as PRIVATE_PHONE_NUMBER
,ppav.address_line_3 as HOME_ADDRESS_UNIT_NUMBER
,ppav.address_line_2 as HOME_ADDRESS_COMPLEX_NAME
,ppav.address_line_1 as HOME_ADDRESS_STREET_NUMBER
,ppav.address_line_4 as HOME_ADDRESS_NAME_STREET
,ppav.addl_address_attribute1 as HOME_ADDRESS_SUBURB_DISTRICT
,ppav.town_or_city as HOME_ADDRESS_CITY_TOWN
,to_char(ppav.postal_code, '0999') as HOME_ADDRESS_POSTAL_CODE
,ppav.region_3 as HOME_ADDRESS_PROVINCE
,(select geography_name
from hz_geographies hg
where 1=1
and (hg.end_date is null or hg.end_date > sysdate)
and hg.geography_type = 'COUNTRY'
and hg.geography_code = ppav.country
and rownum=1) as HOME_ADDRESS_COUNTRY
,ple.name as LEGAL_EMPLOYER
,pplf.attribute2 as MZ_NUIT
,pptt.user_person_type as WORKER_TYPE
,ppos.date_start as HIRE_DATE
,psdf.seniority_date as ENTERPRISE_SENIORITY_DATE
,ppos.actual_termination_date as TERMINATION_DATE
,(select pav.action_name
from per_actions_vl pav
,per_action_occurrences pao
where 1=1
and pav.action_id = pao.action_id
and ppos.actual_termination_date is not null
and pav.action_name not in ('Global Transfer')
and pao.action_occurrence_id = ppos.action_occurrence_id) as
TERMINATION_ACTION
,(select partl.action_reason
from per_action_reasons_b parb
,per_action_reasons_tl partl
,per_action_occurrences pao
where 1=1
and pao.action_reason_id = parb.action_reason_id
and partl.action_reason_id = parb.action_reason_id
and partl.language = userenv('LANG')
and ppos.actual_termination_date is not null
and partl.action_reason not in ('Promotion','Transfer')
and pao.action_occurrence_id = ppos.action_occurrence_id) as
TERMINATION_REASON
,patl.action_name as ASSIGNMENT_ACTION
,part.action_reason as ASSIGNMENT_ACTION_REASON
,paam.effective_start_date as ASSIGNMENT_START_DATE
,paam.effective_end_date as ASSIGNMENT_END_DATE
,per_extract_utility.get_decoded_lookup('CONTRACT_TYPE', pcf.type) as
CONTRACT_TYPE
,pcf.contract_end_date as CONTRACT_END_DATE
,paam.ASSIGNMENT_NUMBER
,pastt.user_status as ASSIGNMENT_STATUS
,bhaou.name as BUSINESS_UNIT
---- ,pjf.job_code as JOB_CODE
,pjft.name JOB_TITLE
,hr_general.decode_lookup('MANAGER_LEVEL', pjf.manager_level) as
MANAGEMENT_LEVEL
,hr_general.decode_lookup('JOB_FUNCTION_CODE', pjf.job_function_code) as
JOB_FUNCTION
,hr_general.decode_lookup('HWB_OCC_LEVEL', pjf.attribute1) as
OCCUPATIONAL_LEVEL
,hr_general.decode_lookup('HWB_OCC_CAT', pjf.attribute2) as
OCCUPATIONAL_CATEGORY
,per_extract_utility.get_decoded_lookup('HWB_OFO_CODE', pjf.attribute3) as
OFO_CODE
,per_extract_utility.get_decoded_lookup('HWB_OFO_SPEC_CODE', pjf.attribute4)
as OFO_SPECIALIZATION_CODE
,dhaou.attribute3 as EMP_DEPARTMENT_NAME_CODE
,dhaou.name as EMP_DEPARTMENT_NAME
---- ,dhaou.attribute4 as EMP_DEPARTMENT_TITLE_CODE
,dhouft.title as EMP_DEPARTMENT_TITLE
---- ,hla.internal_location_code as EMP_LOCATION_CODE
,hla.location_name as EMP_LOCATION_NAME
,per_extract_utility.get_decoded_lookup('HWB_SUP_DEPARTMENT',
paam.ass_attribute2) as EMP_SUB_DEPARTMENT
,per_extract_utility.get_decoded_lookup('HWB_GEOGR_LOC', dhaou.attribute1) as
EMP_GEOGRAPICAL_REGION
,per_extract_utility.get_decoded_lookup('HWB_ORG_BUSINESS_UNIT',
paam.ass_attribute4) as EMP_HWB_BUSINESS_UNIT
,per_extract_utility.get_decoded_lookup('HWB_ORG_HR_FUNCT',paam.ass_attribute
1) as EMP_HR_FUNCTION
---- ,(select fcl.lookup_code
---- from fnd_common_lookups fcl
---- where 1=1
---- and fcl.lookup_type = 'HWB_BRANCH_AS_BU'
---- and fcl.meaning = bhaou.name
---- and rownum=1) as EMP_BRANCH_CODE
,decode(paam.work_at_home,'N','No','Y','Yes', paam.work_at_home) as
WORK_AT_HOME
,per_extract_utility.get_decoded_lookup('EMPLOYEE_CATG',
paam.employee_category) as WORKER_CATEGORY
,per_extract_utility.get_decoded_lookup('EMP_CAT', paam.employment_category)
as PORTFOLIO_APPROVER
,per_extract_utility.get_decoded_lookup('HWB_HRPORTFOLIO_ACCESS',paam.ass_att
ribute6) as PORTFOLIO_ACCESS
,per_extract_utility.get_decoded_lookup('HWB_EARNING_ACCESS',
paam.ass_attribute5) as EARNING_ACCESS
---- ,per_extract_utility.get_decoded_lookup('HOURLY_SALARIED_CODE',
paam.hourly_salaried_code) as EMP_PAYTYPE
,paam.normal_hours as NORMAL_WORKING_HOURS
,hr_general.decode_lookup('FREQUENCY', paam.frequency) as
WORKING_HOURS_FREQUENCY
,per_extract_utility.get_decoded_lookup('ORA_HRX_ZA_NATURE_OF_PERSON',
paam.asg_information1) as NATURE_PERSON
,lmpapf.person_number as LINE_MANAGER_PERSON_NUMBER
,lmppnf.display_name as LINE_MANAGER_NAME
,smpapf.person_number as SALARY_MANAGER_PERSON_NUMBER
,smppnf.display_name as SALARY_MANAGER_NAME
,hmpapf.person_number as HOURS_MANAGER_PERSON_NUMBER
,hmppnf.display_name as HOURS_MANAGER_NAME
,paam.probation_period ||' '||
decode(paam.probation_unit,'D','Days','M','Months','W','Weeks','H','Hours','Y','Yea
rs') as PROBATION_PERIOD
,paam.date_probation_end AS DATE_PROBATION_END
,paam.notice_period ||' '||
decode(paam.notice_period_uom,'D','Days','M','Months','W','Weeks','H','Hours','Y','
Years') as NOTICE_PERIOD
,paam.retirement_age as RETIREMENT_AGE
,paam.retirement_date as RETIREMENT_DATE
,null as SALARY_BASIS_NAME
,null as SALARY
,null as SALARY_START_DATE
,null as SALARY_END_DATE
,null as WORKER_PAYROLL_NAME
,null as PAYROLL_START_DATE
,null as PAYROLL_END_DATE
,to_char(:p_date,'YYYY') - to_char(psdf.seniority_date,'YYYY') as
YEARS_SERVICE
,case when to_char(psdf.seniority_date,'DD') < 15 then
trunc(months_between(:p_date, psdf.seniority_date))
else round(months_between(:p_date, psdf.seniority_date))
end as MONTHS_SERVICE
,(select distinct div.name
from fnd_tree_vl ftvl
,fnd_tree_version_tl ftvt
,per_org_tree_node_rf potnc
,hr_all_organization_units dept
,hr_all_organization_units div
where 1=1
and trunc(sysdate) between dept.effective_start_date and
dept.effective_end_date
and trunc(sysdate) between div.effective_start_date and
div.effective_end_date
and ftvl.tree_code = ftvt.tree_code
and ftvt.language = 'US'
and ftvl.tree_structure_code = 'PER_ORG_TREE_STRUCTURE'
and ftvl.tree_name = 'HOLLYWOODBETS GROUP'
and ftvt.tree_version_name = 'Hollywoodbets Group Feb 2024'
and ftvl.tree_code = potnc.tree_code
and potnc.tree_structure_code = 'PER_ORG_TREE_STRUCTURE'
and ftvl.tree_code = potnc.tree_code
and potnc.distance = 2
and potnc.pk1_value = dept.organization_id
and potnc.ancestor_pk1_value = div.organization_id
and dept.organization_id = paam.organization_id) as DIVISION
from per_person_secured_list_v papf
,per_person_names_f ppnf
,per_all_assignments_m paam
,per_periods_of_service ppos
,per_persons pp
,per_seniority_dates_f psdf
,per_national_identifiers pni
,per_ethnicities pe
,per_legal_employers ple
,per_people_legislative_f pplf
,per_person_types_tl pptt
,per_assignment_status_types_tl pastt
,per_contracts_f pcf
,hr_all_organization_units bhaou
,hr_org_unit_classifications_f bhoucf
,hr_all_organization_units dhaou
,hr_organization_units_f_tl dhouft
,hr_org_unit_classifications_f dhoucf
,hr_locations_all hla
,per_jobs_f pjf
,per_jobs_f_tl pjft
,per_person_addresses_v ppav
,per_passports ppass
,per_disabilities_f pdf
,per_citizenships pc
,per_actions_b pab
,per_actions_tl patl
,per_action_reasons_tl part
,per_action_reasons_b parb
,per_assignment_supervisors_f lmpasf
,per_all_people_f lmpapf
,per_all_assignments_m lmpaam
,per_person_names_f lmppnf
,per_assignment_supervisors_f smpasf
,per_all_people_f smpapf
,per_all_assignments_m smpaam
,per_person_names_f smppnf
,per_assignment_supervisors_f hmpasf
,per_all_people_f hmpapf
,per_all_assignments_m hmpaam
,per_person_names_f hmppnf
where 1=1
and :p_date between papf.effective_start_date and papf.effective_end_date
and :p_date between ppnf.effective_start_date and ppnf.effective_end_date
and :p_date between paam.effective_start_date and paam.effective_end_date
and :p_date between psdf.effective_start_date(+) and psdf.effective_end_date(+)
and :p_date between ple.effective_start_date(+) and ple.effective_end_date(+)
and :p_date between pplf.effective_start_date(+) and pplf.effective_end_date(+)
and :p_date between bhaou.effective_start_date(+) and bhaou.effective_end_date(+)
and :p_date between bhoucf.effective_start_date(+) and bhoucf.effective_end_date(+)
and :p_date between dhaou.effective_start_date(+) and dhaou.effective_end_date(+)
and :p_date between dhouft.effective_start_date(+) and dhouft.effective_end_date(+)
and :p_date between dhoucf.effective_start_date(+) and dhoucf.effective_end_date(+)
and :p_date between hla.effective_start_date(+) and hla.effective_end_date(+)
and :p_date between pjf.effective_start_date(+) and pjf.effective_end_date(+)
and :p_date between pjft.effective_start_date(+) and pjft.effective_end_date(+)
and :p_date between pcf.effective_start_date(+) and pcf.effective_end_date(+)
and :p_date between pdf.effective_start_date(+) and pdf.effective_end_date(+)
and :p_date between lmpasf.effective_start_date(+) and lmpasf.effective_end_date(+)
and :p_date between lmpapf.effective_start_date(+) and lmpapf.effective_end_date(+)
and :p_date between lmpaam.effective_start_date(+) and lmpaam.effective_end_date(+)
and :p_date between lmppnf.effective_start_date(+) and lmppnf.effective_end_date(+)
and :p_date between smpasf.effective_start_date(+) and smpasf.effective_end_date(+)
and :p_date between smpapf.effective_start_date(+) and smpapf.effective_end_date(+)
and :p_date between smpaam.effective_start_date(+) and smpaam.effective_end_date(+)
and :p_date between smppnf.effective_start_date(+) and smppnf.effective_end_date(+)
and :p_date between hmpasf.effective_start_date(+) and hmpasf.effective_end_date(+)
and :p_date between hmpapf.effective_start_date(+) and hmpapf.effective_end_date(+)
and :p_date between hmpaam.effective_start_date(+) and hmpaam.effective_end_date(+)
and :p_date between hmppnf.effective_start_date(+) and hmppnf.effective_end_date(+)
and :p_date between ppav.effective_start_date(+) and ppav.effective_end_date(+)
and :p_date between nvl(pni.issue_date, :p_date) and
nvl(pni.expiration_date, :p_date)
and :p_date between pab.start_date and pab.end_date
and :p_date between parb.start_date(+) and parb.end_date(+)
and (ppos.actual_termination_date is null or ppos.actual_termination_date
>= :p_date)
and papf.person_id = ppnf.person_id
and papf.person_id = paam.person_id
and papf.person_id = ppos.person_id
and paam.period_of_service_id = ppos.period_of_service_id
and ppnf.name_type = 'GLOBAL'
and paam.effective_latest_change = 'Y'
and paam.assignment_type in ('E')
and papf.person_id = pcf.person_id(+)
and ppos.period_of_service_id = pcf.period_of_service_id(+)
and papf.person_id = pp.person_id(+)
and papf.person_id = pe.person_id(+)
and pe.primary_flag(+) = 'Y'
and papf.person_id = ppass.person_id(+)
and papf.person_id = pdf.person_id(+)
and papf.person_id = pc.person_id(+)
and psdf.seniority_date_code(+) = case when paam.assignment_number like '%-%' and
ppos.date_start > '2024-03-01' then
'ORA_PER_MIGR_LESD_W'
else 'ORA_PER_MIGR_ESD_P'
end
and psdf.exit_date is null
and papf.person_id = psdf.person_id(+)
and papf.person_id = pni.person_id(+)
and papf.primary_nid_id = pni.national_identifier_id(+)
and pni.national_identifier_type(+) in ('ORA_HRX_ID_NUMBER',
'NID','ORA_HRX_ALTERNATE3')
and paam.legal_entity_id = ple.organization_id(+)
and ple.status(+) = 'A'
and papf.person_id = pplf.person_id(+)
and paam.person_type_id = pptt.person_type_id(+)
and pptt.language(+) = userenv('LANG')
and paam.assignment_status_type_id = pastt.assignment_status_type_id(+)
and pastt.language(+) = userenv('LANG')
and paam.business_unit_id = bhaou.organization_id(+)
and bhaou.organization_id = bhoucf.organization_id(+)
and bhoucf.status(+) = 'A'
and bhaou.internal_external_flag(+) = 'INT'
and bhoucf.classification_code(+) = 'FUN_BUSINESS_UNIT'
and paam.organization_id = dhaou.organization_id(+)
and dhaou.organization_id = dhouft.organization_id
and dhouft.language = userenv('LANG')
and dhaou.organization_id = dhoucf.organization_id
and dhoucf.status = 'A'
and dhaou.internal_external_flag = 'INT'
and dhoucf.classification_code = 'DEPARTMENT'
and paam.location_id = hla.location_id(+)
and paam.job_id = pjf.job_id(+)
and pjf.job_id = pjft.job_id(+)
and pjft.language(+) = userenv('LANG')
and papf.person_id = ppav.person_id(+)
and ppav.address_type(+) = 'HOME'
and papf.person_id = lmpasf.person_id(+)
and paam.assignment_id = lmpasf.assignment_id(+)
and lmpasf.manager_type(+) = 'LINE_MANAGER'
and lmpasf.manager_id = lmpapf.person_id(+)
and lmpasf.manager_assignment_id = lmpaam.assignment_id(+)
and lmpapf.person_id = lmpaam.person_id(+)
and lmpaam.assignment_type(+) = 'E'
and lmpapf.person_id = lmppnf.person_id(+)
and lmppnf.name_type(+) = 'GLOBAL'
and papf.person_id = smpasf.person_id(+)
and paam.assignment_id = smpasf.assignment_id(+)
and smpasf.manager_type(+) = 'SALARY_MANAGER'
and smpasf.manager_id = smpapf.person_id(+)
and smpasf.manager_assignment_id = smpaam.assignment_id(+)
and smpapf.person_id = smpaam.person_id(+)
and smpaam.assignment_type(+) = 'E'
and smpapf.person_id = smppnf.person_id(+)
and smppnf.name_type(+) = 'GLOBAL'
and papf.person_id = hmpasf.person_id(+)
and paam.assignment_id = hmpasf.assignment_id(+)
and hmpasf.manager_type(+) = 'HOURS_MANAGER'
and hmpasf.manager_id = hmpapf.person_id(+)
and hmpasf.manager_assignment_id = hmpaam.assignment_id(+)
and hmpapf.person_id = hmpaam.person_id(+)
and hmpaam.assignment_type(+) = 'E'
and hmpapf.person_id = hmppnf.person_id(+)
and hmppnf.name_type(+) = 'GLOBAL'
and paam.action_code = pab.action_code
and pab.action_id = patl.action_id
and patl.language = 'US'
and paam.reason_code = parb.action_reason_code(+)
and parb.action_reason_id = part.action_reason_id(+)
and part.language(+) = 'US'
and ple.name in (:p_legal_employer)
and bhaou.name in (:p_business_unit)
and (dhouft.title is null or dhouft.title in (:p_department))
and (hla.location_name is null or hla.location_name in (:p_location))
----and papf.person_number in ('1722','3400')
order by papf.person_number