0% found this document useful (0 votes)
911 views7 pages

BG Absence Duration

This formula calculates employee absence duration in days or hours. It takes in absence start and end dates and times as inputs. It first checks if the start and end dates are defaulted, and if so sets the duration to 0. Otherwise it calculates the number of days between the dates. It then checks if the absence is in hours or days and calculates the duration accordingly, taking into account assignment or position working hours and adjusting for partial start/end days. It finally returns the duration and checks it against various leave policies and eligibility rules.

Uploaded by

Ahmad Al-naqouri
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
911 views7 pages

BG Absence Duration

This formula calculates employee absence duration in days or hours. It takes in absence start and end dates and times as inputs. It first checks if the start and end dates are defaulted, and if so sets the duration to 0. Otherwise it calculates the number of days between the dates. It then checks if the absence is in hours or days and calculates the duration accordingly, taking into account assignment or position working hours and adjusting for partial start/end days. It finally returns the duration and checks it against various leave policies and eligibility rules.

Uploaded by

Ahmad Al-naqouri
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

/*

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'
DEFAULT FOR ASG_NUMBER IS '0'
DEFAULT FOR PER_EMP_NUMBER IS '0'
Default FOR EMP_HIRE_DATE is '0001/01/01 00:00:00'(date)
Default FOR SYSDATE is '0001/01/01 00:00:00'(date)
Default FOR PER_NATIONALITY is 'X'
Default FOR PER_SEX is 'X'
Default FOR PER_MARITAL_STATUS is 'X'
/* local variables */
error_or_warning = ' '
invalid_msg = ' '
duration = '0'
number_of_days = 0
first_day_hours = 0
last_day_hours = 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)
)
/* use of error messages:
if to_num(duration) = 0 then
(
duration = 'FAILED'
invalid_msg = 'HR_ABSENCE_CANNOT_BE_ZERO'
)
*/
)
/*------------------------------------------------------------------------------
*/
Absence_Name=ARB_ABSENCE_NAME(ABSENCE_ATTENDANCE_TYPE_ID)
Emp_Religion=ARB_RELIGION()
CNT=ARB_LEAVE_CNT()
/*------------To Exclude the Holiday Days from the Absence Duration in Case of A
nnual Vacation----------------*/
IF Absence_Name='ÅÌÇÒÉ ÓäæíÉ' or Absence_Name='Annual Leave' Then
(
IF CNT>=5 then
(
duration ='FAILED'
invalid_msg = 'You are not allowed to take more than 5 leaves a
year'
)
ELSE
(
Curr_Hijrah_Year=Substr(ARB_GREGORIAN_TO_HIJRAH(date_start),1,4)
Holiday_Period1=GET_TABLE_VALUE('ARB_HOLIDAY','HIJ',Curr_Hijrah_Year)
Holiday_Period2=GET_TABLE_VALUE('ARB_HOLIDAY','RAMADAN',Curr_Hijrah_Year
)
Holiday_Period3=GET_TABLE_VALUE('ARB_HOLIDAY','NDAY',Curr_Hijrah_Year)
Holiday_Start_Date1=to_date(substr(Holiday_Period1,1,8),'dd/mm/yyyy')
Holiday_End_Date1=to_date(substr(Holiday_Period1,10,8),'dd/mm/yyyy')
Holiday_Start_Date2=to_date(substr(Holiday_Period2,1,8),'dd/mm/yyyy')
Holiday_End_Date2=to_date(substr(Holiday_Period2,10,8),'dd/mm/yyyy')
Holiday_Start_Date3=to_date(substr(Holiday_Period3,1,8),'dd/mm/yyyy')
Holiday_End_Date3=to_date(substr(Holiday_Period3,10,8),'dd/mm/yyyy')
Excluded_Days1=ARB_INTERSECTION_DATE(date_start ,date_end, Holiday_Start
_Date1,Holiday_End_Date1)
Excluded_Days2=ARB_INTERSECTION_DATE(date_start ,date_end, Holiday_Start
_Date2,Holiday_End_Date2)
Excluded_Days3=ARB_INTERSECTION_DATE(date_start ,date_end, Holiday_Start
_Date3,Holiday_End_Date3)
Excluded_Days=Excluded_Days1+Excluded_Days2+Excluded_Days3
IF Excluded_Days<>0 Then
(
duration=to_char(to_num(duration)-Excluded_Days)
)
)
)
ELSE IF Absence_Name='ÅÌÇÒÉ ÒæÇÌ' or Absence_Name='Marriage Leave' Then
(
Previous_Days=ARB_ABSENCE_DAYS2(trunc(EMP_HIRE_DATE),trunc(add_days(date
_start,-1)),'ÅÌÇÒÉ ÒæÇÌ')
IF TO_NUM(duration)>ARB_MARRIAGE_LEAVE_DAYS THEN
(
duration = 'FAILED'
invalid_msg = 'ÚÝæÇð....ÇáÍÏ ÇáÃÞÕì áÅÌÇÒÉ ÇáÒæÇÌ '+to_text(ARB_MARRIAGE_L
)
ELSE IF Previous_Days>0 THEN
(
duration = 'FAILED'
invalid_msg ='Êã ÊÓÌíá ÅÌÇÒÉ ÒæÇÌ áåÐÇ ÇáãæÙÝ ãä ÞÈá'||to_text(Previous_Day
)
ELSE IF PER_MARITAL_STATUS = 'Married' then
(
duration = 'FAILED'
invalid_msg ='áÇ ÊÚØì ÅÌÇÒÉ ÇáÒæÇÌ áãä ßÇä ãÊÒæÌÇ'
)
)
ELSE IF Absence_Name='ÅÌÇÒÉ ÍÌ' or Absence_Name='Hajj Leave' Then
(
Previous_Days=ARB_ABSENCE_DAYS2(trunc(EMP_HIRE_DATE),trunc(SYSDATE),'ÅÌÇÒÉ ÍÌ')
No_Of_Yrs=TRUNC(TRUNC(Months_Between(Add_Days(date_start,1),EMP_HIRE_DAT
E))/12)
IF No_Of_Yrs<1 THEN
(
duration = 'FAILED'
invalid_msg = 'ÅÌÇÒÉ ÇáÍÌ áÇ ÊÚØì ÅáÇ ÈÚÏ ãÑæÑ ÚÇã ãä ÊÇÑíÎ ÇáÊÚííä'
)
ELSE IF Emp_Religion<>'MUSLIM' THEN
(
duration = 'FAILED'
invalid_msg = 'ÅÌÇÒÉ ÇáÍÌ ÝÞØ ááãæÙÝíä ÇáãÓáãíä'
)
ELSE IF TO_NUM(duration)>ARB_HIJ_LEAVE_DAYS THEN
(
duration ='FAILED'
invalid_msg = 'ÚÝæÇð....ÇáÍÏ ÇáÃÞÕì áÅÌÇÒÉ ÇáÍÌ '+chr(10)+to_text(ARB_HIJ_
)
ELSE IF Previous_Days+TO_NUM(duration)> 2 THEN
(
duration = 'FAILED'
invalid_msg ='Êã ÊÓÌíá ÅÌÇÒÉ ÍÌ áåÐÇ ÇáãæÙÝ ãä ÞÈá'||to_text(Previous_Days)
)
)
ELSE IF Absence_Name='ÅÌÇÒÉ ÇÎÊÈÇÑ' or Absence_Name='Exam Leave' Then
(
Saudi_Nationality_Meaning=GET_LOOKUP_MEANING('NATIONALITY','ARB-SA')
IF Saudi_Nationality_Meaning<>PER_NATIONALITY Then
(
duration = 'FAILED'
invalid_msg ='ÅÌÇÒÉ ÇáÇÎÊÈÇÑÇÊ áÇ ÊÚØì ÅáÇ ááãæÙÝ ÇáÓÚæÏí'
)
)
ELSE IF Absence_Name='ÅÌÇÒÉ ãæáæÏ' or Absence_Name='New Baby Leave'Then
(
Status_Meaning=GET_LOOKUP_MEANING('MAR_STATUS','M')
Sex_Meaning=GET_LOOKUP_MEANING('SEX','M')
IF Status_Meaning<>PER_MARITAL_STATUS OR Sex_Meaning <>PER_SEX Then
(
duration = 'FAILED'
invalid_msg ='ÅÌÇÒÉ ÇáãæáæÏ áÇ ÊÚØì ÅáÇ ááãæÙÝ ÇáãÊÒæÌ'
)
ELSE IF TO_NUM(duration)>ARB_BIRTH_LEAVE_DAYS THEN
(
duration ='FAILED'
invalid_msg = 'ÚÝæÇð....ÇáÍÏ ÇáÃÞÕì áÅÌÇÒÉ ÇáãæáæÏ '+chr(10)+to_text(ARB_B
)
)
ELSE IF Absence_Name='ÅÌÇÒÉ æÝÇÉ ÞÑíÈ' or Absence_Name='Death Leave' Then
(
IF TO_NUM(duration)>ARB_DEATH_LEAVE_DAYS THEN
(
duration ='FAILED'
invalid_msg = 'ÚÝæÇð....ÇáÍÏ ÇáÃÞÕì áÅÌÇÒÉ æÝÇÉ ÇáÞÑíÈ '+chr(10)+to_text(A
)
)
ELSE IF Absence_Name='ÅÌÇÒÉ ÚÏÉ' or Absence_Name='Iddah Leave' Then
(
Emp_Status=ARB_MAR_STATUS(Add_Days(date_start,-1))
Sex_Meaning=GET_LOOKUP_MEANING('SEX','F')
IF Sex_Meaning<>PER_SEX Then
(
duration = 'FAILED'
invalid_msg ='ÅÌÇÒÉ ÇáÚÏÉ áÇ ÊÚØì ÅáÇ ááãæÙÝÇÊ'
)
ELSE IF Emp_Religion<>'MUSLIM' THEN
(
duration = 'FAILED'
invalid_msg = 'ÅÌÇÒÉ ÇáÚÏÉ ÝÞØ ááãæÙÝÇÊ ÇáãÓáãÇÊ'
)
ELSE IF Emp_Status<>'M' THEN
(
duration = 'FAILED'
invalid_msg = 'ÅÌÇÒÉ ÇáÚÏÉ ÝÞØ ááãæÙÝÇÊ ÇáãÊÒæÌÇÊ'
)
ELSE IF TO_NUM(duration)>130 THEN
(
duration ='FAILED'
invalid_msg = 'ÚÝæÇð....ÇáÍÏ ÇáÃÞÕì áÅÌÇÒÉ ÇáÚÏÉ 130 íæãÇ ÝÞØ '
)
)
ELSE IF Absence_Name='ÅÌÇÒÉ ÃãæãÉ' or Absence_Name='Maternity Leave' Then
(
Sex_Meaning=GET_LOOKUP_MEANING('SEX','F')
LOA_ANN=ARB_CHECK_LEAVE(trunc(date_start))
IF Sex_Meaning <> PER_SEX or PER_MARITAL_STATUS<>'M' then
(
duration = 'FAILED'
invalid_msg = 'ÅÌÇÒÉ ÇáÇãæãÉ áÇ ÊÚØì ÇáÇ ááãæÙÝÇÊ'
)
ELSE IF LOA_ANN = 1 then
(
duration = 'FAILED'
invalid_msg ='Please Utilize your Annual Balance'
)
)
ELSE IF Absence_Name='ÇÌÇÒÉ ÏÑÇÓÉ' or Absence_Name='Study Leave' Then
(
LOA_ANN=ARB_CHECK_LEAVE(trunc(date_start))
Check_Prv=ARB_ABSENCE_DAYS2(trunc(EMP_HIRE_DATE),trunc(SYSDATE),'Study Leave
')
Saudi_Nationality_Meaning=GET_LOOKUP_MEANING('NATIONALITY','ARB-SA')
IF Saudi_Nationality_Meaning<>PER_NATIONALITY Then
(
duration = 'FAILED'
invalid_msg ='ÅÌÇÒÉ ÇáÏÑÇÓÉ áÇ ÊÚØì ÅáÇ ááãæÙÝ ÇáÓÚæÏí'
)
ELSE IF Check_Prv>0 then
(
duration = 'FAILED'
invalid_msg = 'Study Leave only One Time per service'
)
ELSE IF TO_NUM(duration)>730 THEN
(
duration = 'FAILED'
invalid_msg = 'ÅÌÇÒÉ ÇáÏÑÇÓÉ íÌÈ Çä áÇ ÊÊÌÇæÒ ÓäÊíä'
)
ELSE IF LOA_ANN = 1 then
(
duration = 'FAILED'
invalid_msg ='Please Utilize your Annual Balance'
)
)
ELSE IF Absence_Name='ÅÌÇÒÉ ÛíÑ ãÏÝæÚÉ' or Absence_Name='Unpaid Leave' Then
(
LOA_ANN=ARB_CHECK_LEAVE(trunc(date_start))
IF LOA_ANN = 1 then
(
duration = 'FAILED'
invalid_msg ='Please Utilize your Annual Balance'
)
)
/*--------------------------------*/
return duration, invalid_msg

You might also like