0% found this document useful (0 votes)
205 views12 pages

Absence Calculation

The document defines several functions and packages related to holidays and time off calculations for an HR system. Key details include: 1) A package (XX_HR_PACKAGE) is created with functions to calculate official holiday duration, get absence codes, and count working days between two dates. 2) Functions are registered in the system to lookup absence codes, calculate holidays, and count working days using the package. 3) A fast formula (BG_ABSENCE_DURATION) is defined to calculate employee absence duration in days or hours based on inputs like date range and accounting for holidays and work schedules.

Uploaded by

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

Absence Calculation

The document defines several functions and packages related to holidays and time off calculations for an HR system. Key details include: 1) A package (XX_HR_PACKAGE) is created with functions to calculate official holiday duration, get absence codes, and count working days between two dates. 2) Functions are registered in the system to lookup absence codes, calculate holidays, and count working days using the package. 3) A fast formula (BG_ABSENCE_DURATION) is defined to calculate employee absence duration in days or hours based on inputs like date range and accounting for holidays and work schedules.

Uploaded by

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

Define New Element (MARS Holiday Element)

Saudi HRMS Manager  Total Compensation  Basic  Element Description

Add Security profile For HR: User Type with option Hr with payroll user for OTL Responsibility

Define Element Time Info


OTL Super Administrator  OTL Time Accounting  Element Time Information

Add Holiday Calendar Function


System Administrator  Application Menu
Oracle Time and Labor Holiday Calendar

Define Holiday Calendar


Saudi HRMS Manager  Other Definitions  Holiday Calendar

Create Package
Package Specification
PACKAGE XX_HR_PACKAGE AS

FUNCTION RH_OTL_OFFICIAL_HOLIDAY(V_START_DATE IN DATE,


V_END_DATE IN DATE,V_DURATION IN OUT NUMBER,
V_HOLIDAY_SD IN OUT DATE,V_HOLIDAY_ED IN OUT DATE,
V_FLAG IN VARCHAR2 DEFAULT 'ALL')RETURN NUMBER;
FUNCTION RH_ABSENCE_CODE(V_ABSENCE_ATTENDANCE_TYPE_ID IN NUMBER)RETURN VARCHAR2;

FUNCTION RH_GET_WORKING_DAYS_COUNT (P_FROM_DATE DATE, P_TO_DATE DATE) return number;

END XX_HR_PACKAGE;

Package Body
PACKAGE BODY XX_HR_PACKAGE AS
/***************************************************************************************************************/
/* to calculate the offical holiday duration which lies between two dates */
/***************************************************************************************************************/
FUNCTION RH_OTL_OFFICIAL_HOLIDAY(V_START_DATE IN DATE,V_END_DATE IN DATE,
V_DURATION IN OUT NUMBER,V_HOLIDAY_SD IN OUT DATE,
V_HOLIDAY_ED IN OUT DATE,V_FLAG IN VARCHAR2 DEFAULT 'ALL')RETURN NUMBER AS
Cursor Holiday_Details IS
Select hhd.holiday_date
From hxt_holiday_calendars hhc,hxt_holiday_days hhd
Where upper(hhc.NAME)=upper('MARS Holiday Calendar')
and hhc.id=hhd.hcl_id
and hhd.holiday_date between V_START_DATE and V_END_DATE
and decode(V_FLAG,'ALL','1',substr(upper(hhd.name),1,4))= decode(V_FLAG,'ALL','1',upper(V_FLAG))
Order by 1;
BEGIN
For My_Holiday_Duration In Holiday_Details Loop
V_DURATION:=V_DURATION+1;
End Loop;
For My_Holiday_SD In Holiday_Details Loop
V_HOLIDAY_SD:=My_Holiday_SD.holiday_date;
EXIT ;
End Loop;
For My_Holiday_ED In Holiday_Details Loop
V_HOLIDAY_ED:=My_Holiday_ED.holiday_date;
End Loop;
dbms_output.PUT_LINE(V_FLAG||' '||V_HOLIDAY_SD||' '|| V_HOLIDAY_ED);
Return 0;
END RH_OTL_OFFICIAL_HOLIDAY;
/***************************************************************************************************************/
/* To Get the absence Name by using the absence attendence type ID */
/***************************************************************************************************************/
FUNCTION RH_ABSENCE_CODE(V_ABSENCE_ATTENDANCE_TYPE_ID IN NUMBER)RETURN VARCHAR2 AS
Absence_Code VARCHAR2(100);
CURSOR My_Absence IS SELECT paat.attribute1 Absence_Code
FROM per_absence_attendance_types paat
WHERE
absence_attendance_type_id=V_ABSENCE_ATTENDANCE_TYPE_ID;
BEGIN
FOR My_Detail IN My_Absence LOOP
Absence_Code:=My_Detail.Absence_Code;
END LOOP;
RETURN (Absence_Code);
END RH_ABSENCE_CODE;
/***************************************************************************************************************/
/* To Get the Working Days */
/***************************************************************************************************************/
FUNCTION RH_GET_WORKING_DAYS_COUNT (P_FROM_DATE DATE, P_TO_DATE DATE)
RETURN NUMBER
IS
V_TO_DATE NUMBER := 0;
V_LEAVE_VAL NUMBER := 0;
V_DATE DATE;
V_DAY VARCHAR2 (50);
V_COUNT NUMBER :=0;
SD DATE ;
CURSOR HOLIDAY_DAYS IS
SELECT HHD.HOLIDAY_DATE
FROM HXT_HOLIDAY_CALENDARS HHC
,HXT_HOLIDAY_DAYS HHD
WHERE UPPER(HHC.NAME)=UPPER('MARS HOLIDAY CALENDAR')
AND HHC.ID=HHD.HCL_ID
;
BEGIN
V_TO_DATE := P_TO_DATE - P_FROM_DATE;
V_DATE := P_FROM_DATE;
FOR I IN 1 .. V_TO_DATE + 1
LOOP
SELECT LTRIM (RTRIM (TO_CHAR (V_DATE, 'DY', 'NLS_DATE_LANGUAGE = ENGLISH')))
INTO V_DAY
FROM DUAL
;
dbms_output.PUT_LINE(V_DAY||v_leave_val);
IF ((V_DAY LIKE 'FRI') OR (V_DAY LIKE 'THU')) THEN
V_LEAVE_VAL := NVL (V_LEAVE_VAL, 0) + 1;
END IF;
V_DATE := V_DATE + 1;
END LOOP;
dbms_output.PUT_LINE(v_leave_val);
SD := P_FROM_DATE;
FOR MY_DAYS IN HOLIDAY_DAYS LOOP
DBMS_OUTPUT.PUT_LINE(SD ||'**'||MY_DAYS.HOLIDAY_DATE);
IF MY_DAYS.HOLIDAY_DATE BETWEEN SD AND P_TO_DATE THEN
DBMS_OUTPUT.PUT_LINE(TO_CHAR(MY_DAYS.HOLIDAY_DATE,'DY', 'NLS_DATE_LANGUAGE = ENGLISH'));
IF UPPER(TO_CHAR(MY_DAYS.HOLIDAY_DATE,'DY', 'NLS_DATE_LANGUAGE = ENGLISH')) LIKE 'FRI' OR
UPPER(TO_CHAR(MY_DAYS.HOLIDAY_DATE,'DY', 'NLS_DATE_LANGUAGE = ENGLISH')) LIKE 'THU' THEN
V_COUNT := V_COUNT;
ELSE V_COUNT := V_COUNT +1;
END IF;
DBMS_OUTPUT.PUT_LINE(V_COUNT);
IF SD +1 <= P_TO_DATE THEN
SD := SD +1;
END IF;
DBMS_OUTPUT.PUT_LINE(SD);
END IF;
END LOOP;
V_LEAVE_VAL := FFFUNC.DAYS_BETWEEN (P_TO_DATE, P_FROM_DATE) - V_LEAVE_VAL - V_COUNT + 1;
RETURN V_LEAVE_VAL;
EXCEPTION
WHEN OTHERS THEN RETURN 0;
END RH_GET_WORKING_DAYS_COUNT;
END XX_HR_PACKAGE;

Register Functions

Saudi HRMS Manager  Other Definitions  Formula Functions

RH_ABSENCE_CODE /RH_ABSENCE_CODE

APPS.XX_HR_PACKAGE.RH_ABSENCE_CODE
RH_GET_WORKING_DAYS_COUNT/RH_GET_WORKING_DAYS_COUNT

RH_OTL_OFFICIAL_HOLIDAY/RH_OTL_OFFICAL_HOLIDAY
Fast Formula (BG_ABSENCE_DURATION)

/*
FORMULA NAME: BG_ABSENCE_DURATION
FORMULA TYPE: Quickpaint
DESCRIPTION: Calculates the Employee's Absence
Duration in days or hours. The profile
'HR: Absence Duration Auto Overwrite'
determines if an existing duration value
can change automatically or not.
--
INPUTS:
- days_or_hours: the units of the absence
- date_start: the absence start date
- date_end: the absence end date
- time_start: the absence start time
- time_end: the absence end time
--
DBI Required:
- asg_start_time : the assignment start time
- asg_end_time: the assignment end time
- asg_pos_start_time: the positon start time
- asg_pos_end_time: the position end time
--
Change History
01 Sep 99 jmoyano Created
10 Oct 01 dcasemor end_day was being set to
asg_start_time. Also allowed
hours to be defaulted if no
UOM is set and hours have been
entered.
*/
/* Main Body of Formula */
INPUTS ARE days_or_hours(text),
date_start (date),
date_end (date),
time_start (text),
time_end (text),
ABSENCE_ATTENDANCE_TYPE_ID
/* default values */
DEFAULT FOR days_or_hours IS 'D'
DEFAULT FOR time_start IS '09:00'
DEFAULT FOR time_end IS '17:00'
DEFAULT FOR date_start IS '0001/01/01 00:00:00' (DATE)
DEFAULT FOR date_end IS '4712/12/31 00:00:00' (DATE)
/* database items */
DEFAULT FOR asg_start_time IS '09:00'
DEFAULT FOR asg_end_time IS '17:00'
DEFAULT FOR asg_pos_start_time IS '09:00'
DEFAULT FOR asg_pos_end_time IS '17:00'
/* local variables */
error_or_warning = ' '
invalid_msg = ' '
duration = '0'
number_of_days = 0
first_day_hours = 0
last_day_hours = 0
l_holiday_sd=to_date('4712/12/31 00:00:00')
l_holiday_ed = to_date('4712/12/31 00:00:00')
l_holiday_duration = 0
/* Defaults Section */
/* default values for working day, these are only used if no
working conditions can be found */
begin_day = '09:00'
end_day = '17:00'

IF ((date_start WAS DEFAULTED) or (date_end WAS DEFAULTED)) then


duration = '0'
else
(
number_of_days = days_between(date_end,date_start)
/* absence in hours */
IF days_or_hours = 'H'
OR (days_or_hours WAS DEFAULTED
AND time_start WAS NOT DEFAULTED
AND time_end WAS NOT DEFAULTED) THEN
(
/* look for the assignment values*/
If ((asg_start_time WAS NOT DEFAULTED) and
(asg_end_time WAS NOT DEFAULTED)) then
(
begin_day = asg_start_time
end_day = asg_end_time
)
else
(
/* look for the position values */
if ((asg_pos_start_time WAS NOT DEFAULTED) and
(asg_pos_end_time WAS NOT DEFAULTED)) then
(
begin_day = asg_pos_start_time
end_day = asg_pos_end_time
)
)
/* compute hours per day */
hours_per_day = ((to_num(substr(end_day,1,2))*60 +
to_num(substr(end_day,4,2))) -
(to_num(substr(begin_day,1,2))*60 +
to_num(substr(begin_day,4,2)))) / 60
/* absence takes place during the same day */
IF number_of_days = 0 THEN
duration = to_char(((to_num(substr(time_end,1,2))*60 +
to_num(substr(time_end,4,2))) -
(to_num(substr(time_start,1,2))*60 +
to_num(substr(time_start,4,2)))) / 60)
/* more than one day */
ELSE
(
/* Changes for bug3093970 starts here */
first_day_hours =((to_num(substr(end_day,1,2))*60 +
to_num(substr(end_day,4,2))) -
(to_num(substr(time_start,1,2))*60 +
to_num(substr(time_start,4,2))) ) / 60

last_day_hours = ((to_num(substr(time_end,1,2))*60 +
to_num(substr(time_end,4,2))) -
(to_num(substr(begin_day,1,2))*60 +
to_num(substr(begin_day,4,2))))/60

if first_day_hours <=0
OR first_day_hours > hours_per_day
OR last_day_hours <= 0
OR last_day_hours > hours_per_day THEN
(
/* Leave timings are out off standard timings*/
/* So use 24 hours rule */
first_day_hours = (24*60 -
(to_num(substr(time_start,1,2))*60 +
to_num(substr(time_start,4,2))))/60

last_day_hours = (to_num(substr(time_end,1,2))*60 +
to_num(substr(time_end,4,2)))/60
)
duration = to_char(first_day_hours+last_day_hours)
duration = to_char(to_num(duration) +
(DAYS_BETWEEN(date_end,date_start) - 1)* hours_per_day)
)
/* Changes for bug3093970 ends here */
)
/* absence in days */
ELSE
(
duration = to_char(DAYS_BETWEEN(date_end,date_start) + 1)
)
)
l_absence_code=Mars_ABSENCE_CODE(ABSENCE_ATTENDANCE_TYPE_ID)
/*xx=RH _OTL_OFFICIAL_HOLIDAY(date_start,date_end,l_holiday_duration,l_holiday_sd,l_holiday_ed)*/
duration=to_char( RH_GET_WORKING_DAYS_COUNT(date_start,date_end))
return duration, invalid_msg

IF l_absence_code='ANNUAL' Then
(
xx=RH_OFFICIAL_HOLIDAY(date_start,date_end,l_holiday_duration,l_holiday_sd,l_holiday_ed)
duration=to_char(to_num(duration)-l_holiday_duration)
)

return duration, invalid_msg

You might also like