You are on page 1of 10

/***************** HRMS \ Oracle Payroll **********************

* FORMULA NAME : BG_ABSENCE_DURATION

* FORMULA PURPOSE : Calculate Employee Leave Types

* CREATE BY : Feras Hamdan

* POSITION : Sr. Oracle HCM Consultant

* CREATION DATE :

* COMPANY : PST

* PRORATION :

* SOURCE :

*****************************************************************

* MODIFIED BY :

* MODIFICATION DATE :

* CHANGE DESCRIPTION :

***************************************************************/

ALIAS EMP_HIRE_DATE AS HIRE_DATE

ALIAS PER_EMP_NUMBER AS EMP_NUM

INPUTS ARE days_or_hours(text),

date_start (date),

date_end (date),

time_start (text),

time_end (text) ,

ABS_INFORMATION1 (text),

ABSENCE_ATTENDANCE_TYPE_ID (Number)

/* default values */

DEFAULT FOR days_or_hours IS 'D'


DEFAULT FOR time_start IS '08:00'

DEFAULT FOR time_end IS '15: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)

DEFAULT for HIRE_DATE is '01-JAN-1900' (date)

DEFAULT FOR EMP_NUM IS '0'

/* database items */

DEFAULT FOR asg_start_time IS '08:30'

DEFAULT FOR asg_end_time IS '18:00'

DEFAULT FOR asg_pos_start_time IS '08:30'

DEFAULT FOR asg_pos_end_time IS '18:00'

DEFAULT FOR ABSENCE_ATTENDANCE_TYPE_ID IS 0

DEFAULT FOR PER_SEX IS ' '

/* local variables */

error_or_warning = ' '

invalid_msg = ' '

DURATION = '0'

number_of_days = 0

TOTAL_DAYS= 0

first_day_hours = 0

last_day_hours = 0

begin_day = '08:30'

end_day = '18:00'

PAY_YEAR_START = 0

/*======== Variables for Absences Balance========*/

VALIDATE_LEAVE=0
OSL_YTD = 0

SL_YTD = 0

ATPL_YTD = 0

EXC_YTD = 0

HAJJ_YTD = 0

SIT_YTD = 0

PAT_YTD = 0

OI_YTD = 0

LML_YTD = 0

hourly_value = 0

hourly_value1 = 0

PEL=0

ANNUAL_LEAVE= ' '

DIFF_TWO_TIME = '0,00'

CALENDAR_DAY = 0

validate_date = ' '

/*======== Variables for Absences Balance========*/

Net_ACC = GET_NET_ACCRUAL_CUSTM(4687,date_start ,HIRE_DATE,0)

PAY_YEAR_START = TO_NUM(TO_CHAR(DATE_START,'YYYY'))

AN_YTD = GET_LEAVE_AVAILED(PAY_YEAR_START,date_start,'Annual Leave')

SL_YTD = GET_LEAVE_AVAILED(PAY_YEAR_START,date_start,'Sick Leave')

HAJJ_YTD = GET_LEAVE_AVAILED(PAY_YEAR_START,date_start,'Hajj Leave')

LML_YTD = GET_LEAVE_AVAILED(PAY_YEAR_START,date_start,'Maternity Leave')

PEL_YTD = GET_LEAVE_AVAILED(PAY_YEAR_START,date_start,'Hourly leave')

UNL_YTD = GET_LEAVE_AVAILED(PAY_YEAR_START,date_start,'Unpaid Leave')

EXL_YTD = GET_LEAVE_AVAILED(PAY_YEAR_START,date_start,'Study Leave')

CALENDAR_DAY = CALCULATE_CALENDAR_DAYS(date_start,date_end)

VALIDATE_LEAVE = xx_lv_overlap_valid(date_start,date_end)

validate_date = XX_VALIDATE_DATE(date_start)
/* DIFF_TWO_TIME = to_char(GET_TWO_TIMES(TO_DATE(time_end, 'DD-MM-YYYY hh24:mi')
,TO_DATE(time_start, 'DD-MM-YYYY hh24:mi')))

*/

/*=================================================*/

IF VALIDATE_LEAVE = 0 THEN

duration = 'FAILED'

invalid_msg = ''

ELSE

/* Sick Leave * /

if ABSENCE_ATTENDANCE_TYPE_ID = 17050 THEN

duration = TO_CHAR(DAYS_BETWEEN(date_end,date_start)+1)

IF to_num(duration) > 14 then

duration = 'FAILED'

invalid_msg = ' 14 '

/* END OF SICK LEAVE * /

/* * /

else if ABSENCE_ATTENDANCE_TYPE_ID = 18044 then

duration = TO_CHAR((DAYS_BETWEEN(date_end,date_start) + 1)
)

/* Maternity Leave * /

else if ABSENCE_ATTENDANCE_TYPE_ID = 17044 THEN

duration = TO_CHAR(DAYS_BETWEEN(date_end,date_start)+1)

IF LML_YTD + to_num(duration) > 70 THEN

Duration = 'FAILED'

invalid_msg = ' 70 '

/* Hours in lue */

else if ABSENCE_ATTENDANCE_TYPE_ID = 20045 THEN

hourly_value1 = (((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)

IF validate_date = 'SAT' THEN

duration = TO_CHAR(hourly_value1*1.5)

ELSE IF validate_date = 'FRI' THEN

duration = TO_CHAR(hourly_value1*1.5)
)

ELSE

duration= TO_CHAR(hourly_value1*1.25)

/* END Hours in lue */

/* DAY IN LUE */

else if ABSENCE_ATTENDANCE_TYPE_ID = 20044 THEN

( IF validate_date = 'SAT' OR validate_date = 'FRI' THEN

duration = TO_CHAR(DAYS_BETWEEN(date_end,date_start)+1*1.5)

/* END DAY IN LUE */

/* Annual Leave * /

else if ABSENCE_ATTENDANCE_TYPE_ID = 16044 THEN

duration = TO_CHAR(calculate_working_days(date_start,date_end) - CALENDAR_DAY )

IF TO_NUM(DURATION)> Net_ACC

THEN

Duration = 'FAILED'

invalid_msg = ' ... : '||' '||TO_CHAR(Net_ACC)

/* end of annual leave * /


/* Hourly leave * /

else if ABSENCE_ATTENDANCE_TYPE_ID = 17053 THEN

hourly_value = (((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/8.5)

if ROUND(hourly_value,3) <= (0.469 ) 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))

if ROUND(hourly_value,3) = (0.471 ) then

duration = to_char(4.25)

if ROUND(hourly_value,3) >= (0.473 ) then

duration = to_char(8.5)

if to_num(duration) > Net_ACC then

duration = 'FAILED'

invalid_msg = ''

/* END OF Hourly leave * /

/* Unpaid Hourly Leave */


else if ABSENCE_ATTENDANCE_TYPE_ID = 19044 THEN

hourly_value = (((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/8.5)

if ROUND(hourly_value,3) <= (0.469 ) 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))

if ROUND(hourly_value,3) = (0.471 ) then

duration = to_char(4.25)

if ROUND(hourly_value,3) >= (0.473 ) then

duration = to_char(8.5)

/* Unpaid Hourly Leave */

/* Nursing Hours * /

else if ABSENCE_ATTENDANCE_TYPE_ID = 17047 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)

IF to_num(duration) > 1 then


(duration = 'FAILED'

invalid_msg = ''

/* End of Nursing Hours * /

/* Hajj Leave * /

else if ABSENCE_ATTENDANCE_TYPE_ID = 17048 THEN

IF DAYS_BETWEEN(SYSDATE,HIRE_DATE)+1/365 >=5 THEN

duration = TO_CHAR((DAYS_BETWEEN(date_end,date_start) + 1))

IF to_num(duration) > 14 then

duration= 'FAILED'

invalid_msg = ' 14 '

/* Unpaid Leave * /

else if ABSENCE_ATTENDANCE_TYPE_ID = 14044 THEN

duration = TO_CHAR((DAYS_BETWEEN(date_end,date_start) + 1))

/* Study Leave */

else if ABSENCE_ATTENDANCE_TYPE_ID = 17049 THEN

(
IF DAYS_BETWEEN(SYSDATE,HIRE_DATE)+1/365 >=5 THEN

duration = TO_CHAR(calculate_working_days(date_start,date_end)-CALENDAR_DAY)

IF EXL_YTD+to_num(duration) > 14 then

duration= 'FAILED'

invalid_msg = ' 14 '

return duration,invalid_msg