select papf.person_number,
paaf.assignment_number,
ppnf.full_name,
PAP.PAYROLL_NAME,
PLE.NAME LE_NAME,
paaf.assignment_status_type,
ppos.actual_termination_date,
addr.address_type,
paf.ADDRESS_LINE_1,
paf.ADDRESS_LINE_2,
paf.ADDRESS_LINE_3,
paf.TOWN_OR_CITY,
paf.REGION_2 STATE,
paf.COUNTRY,
paf.POSTAL_CODE,
paf.address_id,
addr.PERSON_ADDR_USAGE_ID
from
per_all_people_f papf,
per_person_names_f ppnf,
per_all_assignments_f paaf,
PER_PERIODS_OF_SERVICE ppos,
pay_payroll_assignments ppasg,
PAY_ASSIGNED_PAYROLLS_DN papd,
pay_all_payrolls_f pap,
per_legal_employers ple,
per_person_addr_usages_f addr,
per_addresses_f paf
where 1=1
and papf.person_id = paaf.person_id
and papf.person_id = ppnf.person_id
and papf.person_id = ppos.person_id
and paaf.period_of_service_id = ppos.period_of_service_id
and paaf.assignment_id = ppasg.hr_assignment_id
AND paaf.work_terms_assignment_id = ppasg.hr_term_id
--and paaf.person_id = ppasg.person_id
and ppasg.payroll_term_id = papd.payroll_term_id(+)
and papd.payroll_id = pap.payroll_id(+)
and paaf.legal_entity_id = ple.organization_id
and paaf.person_id = addr.person_id(+)
and addr.address_id = paf.address_id
and addr.address_type(+) = 'HOME'
and ple.status = 'A'
and paaf.PRIMARY_FLAG ='Y'
--and paaf.ASSIGNMENT_TYPE = 'E'
and ppnf.name_type='GLOBAL'
AND PPOS.date_start = (SELECT max(date_start) FROM PER_PERIODS_OF_SERVICE PPOS_IN WHERE PPOS_IN.person_id = PAPF.person_id)
and trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
and trunc(sysdate) between ppnf.effective_start_date and ppnf.effective_end_date
and Nvl(ppos.actual_termination_date, trunc(sysdate)) between paaf.effective_start_date and paaf.effective_end_date
AND Nvl(ppos.actual_termination_date, trunc(sysdate)) BETWEEN ppasg.start_date AND ppasg.end_date
AND Nvl(ppos.actual_termination_date, trunc(sysdate)) BETWEEN papd.start_date(+) AND papd.end_date(+)
--AND Nvl(ppos.actual_termination_date, trunc(sysdate)) BETWEEN ppasg.start_date AND ppasg.end_date
and trunc(sysdate) between addr.effective_start_date(+) and addr.effective_end_date(+)
and trunc(sysdate) between paf.effective_start_date(+) and paf.effective_end_date(+)
--and PLE.NAME = 'US1 LE'
--and papf.person_number in ('123123')
paaf.assignment_number,
ppnf.full_name,
PAP.PAYROLL_NAME,
PLE.NAME LE_NAME,
paaf.assignment_status_type,
ppos.actual_termination_date,
addr.address_type,
paf.ADDRESS_LINE_1,
paf.ADDRESS_LINE_2,
paf.ADDRESS_LINE_3,
paf.TOWN_OR_CITY,
paf.REGION_2 STATE,
paf.COUNTRY,
paf.POSTAL_CODE,
paf.address_id,
addr.PERSON_ADDR_USAGE_ID
from
per_all_people_f papf,
per_person_names_f ppnf,
per_all_assignments_f paaf,
PER_PERIODS_OF_SERVICE ppos,
pay_payroll_assignments ppasg,
PAY_ASSIGNED_PAYROLLS_DN papd,
pay_all_payrolls_f pap,
per_legal_employers ple,
per_person_addr_usages_f addr,
per_addresses_f paf
where 1=1
and papf.person_id = paaf.person_id
and papf.person_id = ppnf.person_id
and papf.person_id = ppos.person_id
and paaf.period_of_service_id = ppos.period_of_service_id
and paaf.assignment_id = ppasg.hr_assignment_id
AND paaf.work_terms_assignment_id = ppasg.hr_term_id
--and paaf.person_id = ppasg.person_id
and ppasg.payroll_term_id = papd.payroll_term_id(+)
and papd.payroll_id = pap.payroll_id(+)
and paaf.legal_entity_id = ple.organization_id
and paaf.person_id = addr.person_id(+)
and addr.address_id = paf.address_id
and addr.address_type(+) = 'HOME'
and ple.status = 'A'
and paaf.PRIMARY_FLAG ='Y'
--and paaf.ASSIGNMENT_TYPE = 'E'
and ppnf.name_type='GLOBAL'
AND PPOS.date_start = (SELECT max(date_start) FROM PER_PERIODS_OF_SERVICE PPOS_IN WHERE PPOS_IN.person_id = PAPF.person_id)
and trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
and trunc(sysdate) between ppnf.effective_start_date and ppnf.effective_end_date
and Nvl(ppos.actual_termination_date, trunc(sysdate)) between paaf.effective_start_date and paaf.effective_end_date
AND Nvl(ppos.actual_termination_date, trunc(sysdate)) BETWEEN ppasg.start_date AND ppasg.end_date
AND Nvl(ppos.actual_termination_date, trunc(sysdate)) BETWEEN papd.start_date(+) AND papd.end_date(+)
--AND Nvl(ppos.actual_termination_date, trunc(sysdate)) BETWEEN ppasg.start_date AND ppasg.end_date
and trunc(sysdate) between addr.effective_start_date(+) and addr.effective_end_date(+)
and trunc(sysdate) between paf.effective_start_date(+) and paf.effective_end_date(+)
--and PLE.NAME = 'US1 LE'
--and papf.person_number in ('123123')