Oracle HR and Payroll Related Queries

Oracle EBS/Apps R12. ( Oracle HR / Payroll ) Important Queries
Note: All following queries are customized and may not fit in your setup but can give you some idea to get appropriate results. Thanks

Costing Detail Query:

select
paf.ASSIGNMENT_NUMBER, ppf.FULL_NAME ,pet.element_name,pca.CONCATENATED_SEGMENTS,
decode(pc.DEBIT_OR_CREDIT,’D’,pc.COSTED_VALUE) Debit,
decode(pc.DEBIT_OR_CREDIT,’C’,pc.COSTED_VALUE) Credit
from
per_people_f ppf,
per_assignments_f paf,
pay_assignment_actions pav,
pay_payroll_actions ppa,
pay_costs pc,
PAY_COST_ALLOCATION_KEYFLEX pca,
pay_element_types_f pet,
pay_run_results prr,
pay_run_result_values prrv
where ppf.PERSON_ID=paf.PERSON_ID
and paf.ASSIGNMENT_ID=pav.ASSIGNMENT_ID
and paf.PRIMARY_FLAG=’Y’
and ppf.EMPLOYEE_NUMBER=:p_emp_no
and pav.PAYROLL_ACTION_ID=ppa.PAYROLL_ACTION_ID
and trunc(ppa.EFFECTIVE_DATE) between :p_start_date and :p_end_date
and pav.ASSIGNMENT_ACTION_ID=pc.ASSIGNMENT_ACTION_ID
and pc.COST_ALLOCATION_KEYFLEX_ID=pca.COST_ALLOCATION_KEYFLEX_ID
and pet.ELEMENT_TYPE_ID=prr.ELEMENT_TYPE_ID
and prr.RUN_RESULT_ID=prrv.RUN_RESULT_ID
and pc.RUN_RESULT_ID=prrv.RUN_RESULT_ID
and pc.INPUT_VALUE_ID=prrv.INPUT_VALUE_ID
and :p_end_date between pet.EFFECTIVE_START_DATE and pet.EFFECTIVE_END_DATE
and ppf.EFFECTIVE_END_DATE = (select max(effective_end_date) from per_people_f where person_id=ppf.PERSON_ID)
and paf.EFFECTIVE_END_DATE = (select max(effective_end_date) from per_assignments_f where assignment_id=paf.ASSIGNMENT_ID)

 

Query to Find of Number of Working Days in Months.

SELECT themonth, count(theday) cnt
FROM ( SELECT TO_CHAR(TRUNC(SYSDATE,’YY’)+LEVEL-1,’Month’) themonth
, TO_CHAR(TRUNC(SYSDATE,’YY’)+LEVEL-1,’DY’) theday
FROM dual
CONNECT BY LEVEL <= ADD_MONTHS(TRUNC(SYSDATE,’YY’),12)-TRUNC(SYSDATE,’YY’)
)
WHERE theday NOT IN (‘SAT’,’SUN’)
GROUP BY themonth
ORDER BY TO_DATE(themonth,’MM’)

 

Query to to find the Employee Supervisor name

SELECT papf1.full_name supervisor_nameFrom apps.per_all_people_f papf,apps.per_all_assignments_f paaf,apps.per_all_people_f papf1WHERE papf.person_id = paaf.person_idAND paaf.primary_flag = ‘Y’AND paaf.assignment_type = ‘E’AND paaf.supervisor_id = papf1.person_idAND papf1.current_employee_flag = ‘Y’AND papf.business_group_id = paaf.business_group_idAND SYSDATE BETWEEN papf.effective_start_date and papf.effective_end_dateAND SYSDATE BETWEEN paaf.effective_start_date AND paaf.effective_end_dateAND SYSDATE BETWEEN papf1.effective_start_date AND papf1.effective_end_dateAND papf.employee_number = :p_emp_number;

Query to find out payroll Costing Detail  /  “How to find out payroll costed accounts” / “Query to find out Payroll Charged Accounts”.

SELECT distinct d.EMPLOYEE_NUMBER,d.FULL_NAME,a.CONCATENATED_SEGMENTS, a.element_name,decode(a.debit_or_credit,’Debit’,COSTED_VALUE,”) Debit  ,
decode(debit_or_credit,’Credit’,COSTED_VALUE,”) Credit
FROM  pay_costs_v a, pay_assignment_actions_v b,per_assignments_x c,per_people_x d
where     d.EMPLOYEE_NUMBER= nvl(:p_emp_no,d.EMPLOYEE_NUMBER)
and   trunc (b.EFFECTIVE_DATE)  between :p_from_date and :p_to_date
and a.ASSIGNMENT_ACTION_ID=b.ASSIGNMENT_ACTION_ID
and  b.ASSIGNMENT_ID=c.ASSIGNMENT_ID
and c.PERSON_ID=d.PERSON_ID

 

Query to Find All Active Employees and Current Salary.

select EMPLOYEE_NUMBER,a.FULL_NAME,x.USER_PERSON_TYPE, c.PROPOSED_SALARY_n Basi_Salary–,c.CHANGE_DATE–,c.*
from per_people_f A,per_assignments_f b,pER_PAY_pROposals c
,per_person_types x
, per_person_type_usages_f e
where a.PERSON_ID=b.PERSON_ID
and b.ASSIGNMENT_ID=C.ASSIGNMENT_ID
and a.EMPLOYEE_NUMBER is not null
–and a.EMPLOYEE_NUMBER=:emp_num
and c.CHANGE_DATE = (select max(d.CHANGE_DATE) from pER_PAY_pROposals d where d.ASSIGNMENT_ID=b.ASSIGNMENT_ID and d.approved = ‘Y’)
–and c.CHANGE_DATE>=:change_date
and b.PAYROLL_ID=62
and :p_effective_date between a.EFFECTIVE_START_DATE and a.EFFECTIVE_END_DATE
and :p_effective_date between b.EFFECTIVE_START_DATE and b.EFFECTIVE_END_DATE
and a.PERSOn_id = e.PERSON_ID
and a.EFFECTIVE_START_DATE between e.EFFECTIVE_START_DATE and e.EFFECTIVE_END_DATE
and e.PERSON_TYPE_ID = x.PERSON_TYPE_ID
and x.SYSTEM_PERSON_TYPE = ‘EMP’

 

 

 

Query fo Find out all Earning and Deduction Elements and values after Payroll Run

SELECT ppf.employee_number,ppf.person_id,ppf.full_name,ppa.TIME_PERIOD_ID,ppa.EFFECTIVE_DATE,TP.PERIOD_NAME,paf.ORGANIZATION_ID,
sum(decode(pec.CLASSIFICATION_NAME,’Earnings’,to_number(rrv.result_value),
0)
) Earnings,
sum(decode(pec.CLASSIFICATION_NAME,’Voluntary Deductions’,to_number(rrv.result_value),
‘Involuntary Deductions’,to_number(rrv.result_value),
‘Employer Charges’,to_number(rrv.result_value),
0)
) Deductions
–ety.element_name,ety.CLASSIFICATION_ID
— PD.SEGMENT5  POSITION_NO,PD.SEGMENT6 POSITION_NAME,
FROM per_people_x ppf,
per_assignments_x paf,
pay_assignment_actions pas,
pay_payroll_actions ppa,
pay_run_results rr,
pay_run_result_values rrv,
pay_element_types_f ety,
pay_input_values_F I,
PER_TIME_PERIODS TP,
PAY_ELEMENT_CLASSIFICATIONS_VL pec
WHERE ppf.person_id = paf.person_id
AND paf.assignment_id = pas.assignment_id
AND pas.assignment_action_id = rr.assignment_action_id
AND ppa.payroll_action_id = pas.payroll_action_id
AND rr.element_type_id = ety.element_type_id
AND i.element_type_id = ety.element_type_id
AND rrv.run_result_id = rr.run_result_id
AND rrv.input_value_id = i.input_value_id
and  TP.TIME_PERIOD_ID = PPA.TIME_PERIOD_ID
and ety.CLASSIFICATION_ID=pec.CLASSIFICATION_ID
AND i.name = ‘Pay Value’
—   AND HR_GENERAL.DECODE_LATEST_POSITION_DEF_ID(PAF.POSITION_ID) = PD.POSITION_DEFINITION_ID
and ppa.EFFECTIVE_DATE  BETWEEN    :p_st_effect_date  AND  :p_end_effect_date
and ppf.employee_number  = nvl(:p_emp_number,ppf.employee_number)
group by  ppf.full_name,ppa.TIME_PERIOD_ID,effective_date,–To_Number(Wassa_HR_PACKAGE.Nid_Salary_By_Date(paf.assignment_id,ppa.EFFECTIVE_DATE,’N’)),
ppf.employee_number,ppf.person_id ,–PD.SEGMENT5 ,PD.SEGMENT6,
TP.period_name,paf.ORGANIZATION_ID

Query for Oracle Payroll Salary Slip /  Salary Slip Detail Report Query / How to find out detail of salary slip/ Element wise Landscape Salary Slip at Payroll Run Levle  or quick pay level

Note:  I have hardcoded element names. You can also hardcode your elements to get Landscaped salary slip.

SELECT ppf.employee_number,ppf.person_id,ppf.full_name,ppa.TIME_PERIOD_ID,ppa.EFFECTIVE_DATE  ,TP.PERIOD_NAME,
sum(decode(ety.element_name,’Basic Salary’                         ,TO_NUMBER(rrv.result_value),
‘Basic Sick Leave Payment’             ,TO_NUMBER(rrv.result_value),
‘Basic Out Work Incident Leave Payment’,TO_NUMBER(rrv.result_value),
0)) Earned_salary,
/********************************************************************************************************/
sum(decode(ety.element_name,’Transportation Allowance’                      ,TO_NUMBER(rrv.result_value),
‘Transportation Sick Leave Payment’             ,TO_NUMBER(rrv.result_value),
‘Transportation Out Work Incident Leave Payment’,TO_NUMBER(rrv.result_value),
0)) Transportation_allowance,
/*************************************************************************************************************/
sum(decode(ety.element_name,’Work Type Allowance’                      ,TO_NUMBER(rrv.result_value),
‘Work Type Sick Leave Payment’             ,TO_NUMBER(rrv.result_value),
‘Work Type Out Work Incident Leave Payment’,TO_NUMBER(rrv.result_value),
0)) worktype_allowance,
/***************************************************************************************************************/
sum(decode(ety.element_name,’Damages Allowance’                      ,TO_NUMBER(rrv.result_value),
‘Damages Sick Leave Payment’             ,TO_NUMBER(rrv.result_value),
‘Damages Out Work Incident Leave Payment’,TO_NUMBER(rrv.result_value),
0)) Damage_allowance,
/*****************************************************************************************************************/
sum(decode(ety.element_name,’Danger Allowance’                      ,TO_NUMBER(rrv.result_value),
‘Danger Sick Leave Payment’             ,TO_NUMBER(rrv.result_value),
‘Danger Out Work Incident Leave Payment’,TO_NUMBER(rrv.result_value),
0)) Danger_allowance,
/*************************************************************************************************************/
sum(decode(ety.element_name,’Inflation Allowance’    ,TO_NUMBER(rrv.result_value),0)) Inflation_Allowance,
/*********************************************************  Deductions  ************************************************/
sum(decode(ety.element_name,’Loan Recovery’         ,TO_NUMBER(rrv.result_value),0)) Loan_recovery,
sum(decode(ety.element_name,’Loan Recovery Housing’ ,TO_NUMBER(rrv.result_value),0)) Loan_Recovery_Housing,
sum(decode(ety.element_name,’Loan Recovery Others’  ,TO_NUMBER(rrv.result_value),0)) Loan_Recovery_Others,
sum(decode(ety.element_name,’Housing Deduction’     ,TO_NUMBER(rrv.result_value),0)) Housing_Deduction,
sum(decode(ety.element_name,’Penalty’               ,TO_NUMBER(rrv.result_value),0)) Penalty,
/***********************************************************************************************************************/
sum(decode(ety.element_name,’Civil Pension’                      ,TO_NUMBER(rrv.result_value),
‘Social Insurance’             ,TO_NUMBER(rrv.result_value),
0)) Civil_pension,
/************************************************************************************************************************************/
sum(decode(ety.element_name,’In Out Leave Deduction’ ,TO_NUMBER(rrv.result_value),0)) In_Out_Leave_Deduction,
sum(decode(ety.element_name,’Unpaid Leave Deduction’ ,TO_NUMBER(rrv.result_value),0)) Unpaid_Leave_Deduction,
sum(decode(ety.element_name,’Retrieve Mony Recovery’ ,TO_NUMBER(rrv.result_value),0)) Retrieve_Mony_Recovery
FROM per_people_x ppf,
per_assignments_x paf,
pay_assignment_actions pas ,
pay_payroll_actions ppa,
pay_run_results rr,
pay_run_result_values rrv,
pay_element_types_f ety,
pay_input_values_F I ,
PER_TIME_PERIODS TP
—     PER_POSITION_DEFINITIONS PD
— PAY_INPUT_VALUES_F
WHERE ppf.person_id = paf.person_id
AND paf.assignment_id = pas.assignment_id
AND pas.assignment_action_id = rr.assignment_action_id
AND ppa.payroll_action_id = pas.payroll_action_id
AND rr.element_type_id = ety.element_type_id
AND i.element_type_id = ety.element_type_id
AND rrv.run_result_id = rr.run_result_id
AND rrv.input_value_id = i.input_value_id
and  TP.TIME_PERIOD_ID = PPA.TIME_PERIOD_ID
AND i.name = ‘Pay Value’
—   AND HR_GENERAL.DECODE_LATEST_POSITION_DEF_ID(PAF.POSITION_ID) = PD.POSITION_DEFINITION_ID
and ppa.EFFECTIVE_DATE  BETWEEN    :P_FROM_DATE      AND  :P_TO_DATE
and ppf.employee_number    = :P_Employee_number
–in(34000/*1546014859,14666,35343,15201,15202*/)
group by  ppf.full_name,ppa.TIME_PERIOD_ID,effective_date,
ppf.employee_number,ppf.person_id ,–PD.SEGMENT5 ,PD.SEGMENT6,
TP.period_name
order  by  ppa.EFFECTIVE_DATE