select
(select haouv.name from hr_all_organization_units_vl haouv where x.business_group_id=haouv.organization_id) business_group,
nvl(papf.employee_number,papf.npw_number) employee_number,
papf.full_name employee_name,
x.assignment_number,
haouv2.name organization,
(select pjv.name from per_jobs_vl pjv where x.job_id=pjv.job_id) job,
(select hapft.name from hr_all_positions_f_tl hapft where x.position_id=hapft.position_id and hapft.language=userenv('lang')) position,
(select pgv.name from per_grades_vl pgv where x.grade_id=pgv.grade_id) grade,
(select hlav.location_code from hr_locations_all_vl hlav where x.location_id=hlav.location_id) location,
(select papf2.full_name from per_all_people_f papf2 where x.supervisor_id=papf2.person_id and x.change_date between papf2.effective_start_date and papf2.effective_end_date) supervisor,
(select pap.payroll_name from pay_all_payrolls_f pap where x.payroll_id=pap.payroll_id and x.change_date between pap.effective_start_date and pap.effective_end_date) payroll,
x.change_date,
x.changes,
(select haouv.name from hr_all_organization_units_vl haouv where x.previous_organization_id=haouv.organization_id) previous_organization,
(select pjv.name from per_jobs_vl pjv where x.previous_job_id=pjv.job_id) previous_job,
(select hapft.name from hr_all_positions_f_tl hapft where x.previous_position_id=hapft.position_id and hapft.language=userenv('lang')) previous_position,
(select pgv.name from per_grades_vl pgv where x.previous_grade_id=pgv.grade_id) previous_grade,
(select hlav.location_code from hr_locations_all_vl hlav where x.previous_location_id=hlav.location_id) previous_location,
(select papf2.full_name from per_all_people_f papf2 where x.previous_supervisor_id=papf2.person_id and x.change_date between papf2.effective_start_date and papf2.effective_end_date) previous_supervisor,
(select pap.payroll_name from pay_all_payrolls_f pap where x.previous_payroll_id=pap.payroll_id and x.change_date between pap.effective_start_date and pap.effective_end_date) previous_payroll,
(select pastt.user_status from per_assignment_status_types_tl pastt where x.previous_status_type_id=pastt.assignment_status_type_id and pastt.language=userenv('lang')) previous_assignment_status,
(select pastt.user_status from per_assignment_status_types_tl pastt where x.assignment_status_type_id=pastt.assignment_status_type_id and pastt.language=userenv('lang')) assignment_status,
xxen_util.meaning(x.previous_employment_category,'EMP_CAT',3) previous_employment_category,
xxen_util.meaning(x.employment_category,'EMP_CAT',3) employment_category,
(select ppb.name from per_pay_bases ppb where x.previous_pay_basis_id=ppb.pay_basis_id) previous_salary_basis,
(select ppb.name from per_pay_bases ppb where x.pay_basis_id=ppb.pay_basis_id) salary_basis,
x.previous_normal_hours,
x.normal_hours,
(select ppg.group_name from pay_people_groups ppg where x.previous_people_group_id=ppg.people_group_id) previous_people_group,
(select ppg.group_name from pay_people_groups ppg where x.people_group_id=ppg.people_group_id) people_group,
xxen_util.meaning(x.change_reason,decode(x.assignment_type,'C','CWK_ASSIGN_REASON','EMP_ASSIGN_REASON'),3) assignment_change_reason,
xxen_util.yes(x.primary_flag) primary_assignment,
xxen_util.user_name(x.last_updated_by) last_updated_by,
xxen_util.client_time(x.last_update_date) last_update_date
from
(
select
case
when w.row_type=2 then 'Assignment End'
when paaf0.assignment_id is null then 'New Assignment'
else
ltrim(
decode(w.organization_id,paaf0.organization_id,null,', Organization')||
decode(w.job_id,paaf0.job_id,null,', Job')||
decode(w.position_id,paaf0.position_id,null,', Position')||
decode(w.grade_id,paaf0.grade_id,null,', Grade')||
decode(w.location_id,paaf0.location_id,null,', Location')||
decode(w.supervisor_id,paaf0.supervisor_id,null,', Supervisor')||
decode(w.payroll_id,paaf0.payroll_id,null,', Payroll')||
decode(w.assignment_status_type_id,paaf0.assignment_status_type_id,null,', Assignment Status')||
decode(w.employment_category,paaf0.employment_category,null,', Employment Category')||
decode(w.pay_basis_id,paaf0.pay_basis_id,null,', Salary Basis')||
decode(w.normal_hours,paaf0.normal_hours,null,', Normal Hours')||
decode(w.people_group_id,paaf0.people_group_id,null,', People Group'),
', ')
end changes,
decode(w.row_type,1,paaf0.organization_id) previous_organization_id,
decode(w.row_type,1,paaf0.job_id) previous_job_id,
decode(w.row_type,1,paaf0.position_id) previous_position_id,
decode(w.row_type,1,paaf0.grade_id) previous_grade_id,
decode(w.row_type,1,paaf0.location_id) previous_location_id,
decode(w.row_type,1,paaf0.supervisor_id) previous_supervisor_id,
decode(w.row_type,1,paaf0.payroll_id) previous_payroll_id,
decode(w.row_type,1,paaf0.assignment_status_type_id) previous_status_type_id,
decode(w.row_type,1,paaf0.employment_category) previous_employment_category,
decode(w.row_type,1,paaf0.pay_basis_id) previous_pay_basis_id,
decode(w.row_type,1,paaf0.normal_hours) previous_normal_hours,
decode(w.row_type,1,paaf0.people_group_id) previous_people_group_id,
w.*
from
(
select /*+ no_merge */
rowgen.column_value row_type,
decode(rowgen.column_value,1,paaf.effective_start_date,paaf.effective_end_date) change_date,
paaf.*
from
per_all_assignments_f paaf,
table(xxen_util.rowgen(2)) rowgen
where
1=1 and
paaf.assignment_type in ('E','C') and
decode(rowgen.column_value,1,paaf.effective_start_date,paaf.effective_end_date)>=:change_date_from and
decode(rowgen.column_value,1,paaf.effective_start_date,paaf.effective_end_date)<:change_date_to+1
) w,
(select paaf0.* from per_all_assignments_f paaf0 where paaf0.assignment_type in ('E','C')) paaf0,
per_all_assignments_f paaf1
where
w.assignment_id=paaf0.assignment_id(+) and
w.effective_start_date-1=paaf0.effective_end_date(+) and
w.assignment_id=paaf1.assignment_id(+) and
w.effective_end_date+1=paaf1.effective_start_date(+) and
(w.row_type=1 or paaf1.assignment_id is null and w.effective_end_date<to_date('31-12-4712','DD-MM-YYYY'))
) x,
per_all_people_f papf,
hr_all_organization_units_vl haouv2
where
2=2 and
x.changes is not null and
x.person_id=papf.person_id and
x.change_date between papf.effective_start_date and papf.effective_end_date and
x.organization_id=haouv2.organization_id
order by
papf.full_name,
x.assignment_number,
x.change_date,
x.row_type |