You are on page 1of 9

/*

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 Apr 09 manohar.v Created
20 May 09 sameer.j Modified for formatting
*/

/* Alias Section */
ALIAS ABSENCES_DELIVERY_DATE AS Delivery_Date

/* Default Values Section */


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)
DEFAULT FOR ASG_PROB_END_DATE is '0001/01/01 00:00:00' (DATE)
DEFAULT FOR EMP_HIRE_DATE is '0001/01/01 00:00:00' (DATE)
DEFAULT FOR PER_SEX IS 'XX'
DEFAULT FOR PER_NATIONALITY IS 'XX'
DEFAULT FOR Delivery_Date IS 'XX'

/* Database Items Section */


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 PER_MARITAL_STATUS is 'XX'

/* 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(TEXT)

/* local variables */
l_leave_name = GET_ABSENCE_TYPE(absence_attendance_type_id)
error_or_warning = ' '
invalid_msg = ' '
duration = '0'
v_dur = 0
number_of_days = 0
first_day_hours = 0
last_day_hours = 0
p_year = to_char(date_end,'YYYY')

/* 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
( /* Start Outer Else */
number_of_days = days_between(date_start,date_end)
/* 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 ( /* Start Inner Else */
/************* Handle Incorrect Dates
*************************************************/
IF (Date_End < Date_Start)
THEN
(
v_duration = days_between(Date_End,Date_Start)+1
duration = 'FAILED'
invalid_msg = 'Please check the end date it should be always greater then start
date'
return duration,invalid_msg
)
/************* ANNUAL LEAVE
***********************************************************/
IF (l_leave_name = 'Annual Leave') THEN (
v_duration = days_between(date_end,date_start)+1
duration = to_char(v_duration)
Tot_Leaves = v_duration +
GET_COMMITTED_LEAVE_DAYS(absence_attendance_type_id,p_year)

IF (ASG_PROB_END_DATE > date_end) THEN (


duration = 'FAILED'
invalid_msg = 'Employee is under Probation'
)
ELSE (
IF (Tot_Leaves > XXDLALA_ANNUAL_LEAVE_MAX_DAYS) THEN (
duration = 'FAILED'
invalid_msg = 'Annual leave should not exceed '||
to_char(XXDLALA_ANNUAL_LEAVE_MAX_DAYS)||' calendar days.'
)
)
)

/************* Death of Husband Leave ********************/


IF (l_leave_name = 'Death of Husband Leave') THEN (
v_duration = days_between(date_end,date_start)+1
duration = to_char(v_duration)

IF (PER_SEX = 'Male') THEN (


duration = 'FAILED'
invalid_msg = 'Only female are eligible for Death of Husband Leave'
)
ELSE (
IF (PER_MARITAL_STATUS = 'Single') THEN (
duration = 'FAILED'
invalid_msg = 'Only Married female employees are eligible for Death of
Husband Leave'
)
ELSE (
IF (Delivery_date > to_char(date_start)) and (Delivery_date <
to_char(date_end)) THEN (
v_dur = days_between(to_date(Delivery_date),date_start)+1
duration = to_char(v_dur)
v_duration = days_between(date_end,date_start)+1
duration = to_char(v_duration)
IF (v_duration > v_dur) THEN (
duration = 'FAILED'
invalid_msg = 'Employee is pregnant, therefore Death of Husband Leave
is allowed up to delivery date of the child.'
)
)
ELSE (
Max_days = GET_MAX_LEAVE_DAYS(date_start)
v_duration = days_between(date_end,date_start)+1
duration = to_char(v_duration)
Max_days = GET_MAX_LEAVE_DAYS(date_start)
IF (v_duration > Max_days) THEN (
duration = 'FAILED'
invalid_msg = 'Maximum duration for Death of Husband Leave is '||
to_char(Max_days)||' days.Duration entered is '||to_char(v_duration)||' days.'
)
)
)
)
)
/************* MATERNITY LEAVE
********************************************************/
IF (l_leave_name = 'Maternity Leave') THEN
(
v_duration = days_between(date_end,date_start)+1
duration = to_char(v_duration)

IF (PER_SEX = 'Male')
THEN
(
duration = 'FAILED'
invalid_msg = 'Only female are eligible for Maternity Leave'
)

IF ((MONTHS_BETWEEN(date_start,EMP_HIRE_DATE )/12) < 1)


THEN
(
duration = 'FAILED'
invalid_msg = 'Employee is only eligible to avail Maternity Leave if service
period is more than 1 year'
)
IF (v_duration > XXDLALA_MARENITY_LEAVE_MAX_DAYS)
THEN
(
duration = 'FAILED'
invalid_msg = 'Duration of Maternity Leave should be a maximum of '||
to_char(XXDLALA_MARENITY_LEAVE_MAX_DAYS)||'
Calendar days.'
)
)
/*********** Sick Leave Full Paid Absence
*********************************************/
IF (l_leave_name = 'Sick Leave')
THEN
(
v_duration = DAYS_BETWEEN(date_end,date_start) + 1
duration = to_char(v_duration)
Tot_Leaves = v_duration +
GET_COMMITTED_LEAVE_DAYS(absence_attendance_type_id,p_year)

IF (MONTHS_BETWEEN(date_start,EMP_HIRE_DATE ) < 3)
THEN
(
duration = 'FAILED'
invalid_msg = 'Employee is only eligible to avail Sick Leave if service
period is more than 3 months'
)
IF (Tot_Leaves > XXDLALA_SICK_LEAVE_FULL_PAID_LEAVE_MAX_DAYS)
THEN
(
duration = 'FAILED'
invalid_msg = 'Duration of Sick Leave Full Paid Leave should be maximum of
'||to_char
(XXDLALA_SICK_LEAVE_FULL_PAID_LEAVE_MAX_DAYS)||' Calendar days.'
)
)
/************* Sick Leave Half Paid Absence
********************************************/
IF (l_leave_name = 'Sick Leave Half Paid')
THEN
(
v_duration = DAYS_BETWEEN(date_end,date_start) + 1
duration = to_char(v_duration)
Tot_Leaves = v_duration +
GET_COMMITTED_LEAVE_DAYS(absence_attendance_type_id,p_year)
IF (MONTHS_BETWEEN(date_start,EMP_HIRE_DATE ) < 3)
THEN
(
duration = 'FAILED'
invalid_msg = 'Employee is only eligible to avail Sick Leave if service
period is more than 3 months'
)
IF (Tot_Leaves > XXDLALA_SICK_LEAVE_HALF_PAID_LEAVE_MAX_DAYS)
THEN
(
duration = 'FAILED'
invalid_msg = 'Duration of Sick Leave Half Paid Leave should be maximum of
'||to_char
(XXDLALA_SICK_LEAVE_HALF_PAID_LEAVE_MAX_DAYS)||' Calendar days.'
)
)
/************* HAJJ LEAVE
**************************************************************/
IF (l_leave_name = 'Hajj Leave')
THEN
(
v_duration = days_between(date_end,date_start)+1
duration = to_char(v_duration)
IF (GET_RELIGION() <> 'Muslim')
THEN
(
duration = 'FAILED'
invalid_msg = 'Only Muslim employee are eligible for Hajj Leave'
)
IF ((MONTHS_BETWEEN(date_start,EMP_HIRE_DATE )/12) < 2)
THEN
(
duration = 'FAILED'
invalid_msg = 'Employee is eligible to avail Hajj Leave only if the service
period is more then 2 years'
)
IF (v_duration > XXDLALA_HAJJ_LEAVE_MAX_DAYS)
THEN
(
duration = 'FAILED'
invalid_msg = 'Duration of Hajj Leave should be a maximum of '||
to_char(XXDLALA_HAJJ_LEAVE_MAX_DAYS)||' Calendar days.'
)
IF (GET_LEAVE_TIMES(absence_attendance_type_id) > 0)
THEN
(
duration = 'FAILED'
invalid_msg = 'Employee has already taken Hajj Leave'
)
)
/************* CONDOLENCE LEAVE
********************************************************/
IF (l_leave_name = 'Condolence Leave')
THEN
(
v_duration = days_between(date_end,date_start)+1
duration = to_char(v_duration)
Tot_Leaves = v_duration +
GET_COMMITTED_LEAVE_DAYS(absence_attendance_type_id,p_year)

IF (ASG_PROB_END_DATE > date_end)


THEN
(
duration = 'FAILED'
invalid_msg = 'Employee is under Probation'
)
IF (Tot_Leaves > XXDLALA_CONDOLENCE_LEAVE_MAX_DAYS)
THEN
(
duration = 'FAILED'
invalid_msg = 'Condolence Leave cannot exceed '||
to_char(XXDLALA_CONDOLENCE_LEAVE_MAX_DAYS)||' calendar days.'
)
)
/************* MARRIAGE LEAVE
**********************************************************/
IF (l_leave_name = 'Marriage Leave')
THEN
(
v_duration = days_between(Date_End,Date_Start)+1
duration = to_char(v_duration)
IF (ASG_PROB_END_DATE > date_end)
THEN
(
duration = 'FAILED'
invalid_msg = 'Employee is under Probation'
)
IF (v_duration > XXDLALA_MARRIAGE_LEAVE_MAX_DAYS)
THEN
(
duration = 'FAILED'
invalid_msg = 'Marriage Leave cannot exceed '||
to_char(XXDLALA_MARRIAGE_LEAVE_MAX_DAYS)||' calendar days.'
)
IF (GET_LEAVE_TIMES(absence_attendance_type_id) > 0)
THEN
(
duration = 'FAILED'
invalid_msg = 'Employee has already taken Marriage Leave'
)
)
/************* SPECIAL LEAVE
**********************************************************/
IF (l_leave_name = 'Special Leave')
THEN
(
v_duration = days_between(Date_End,Date_Start)+1
duration = to_char(v_duration)
Tot_Leaves = v_duration +
GET_COMMITTED_LEAVE_DAYS(absence_attendance_type_id,p_year)
IF ((Tot_Leaves > XXDLALA_SPECIAL_LEAVE_MAX_DAYS))
THEN
(
duration = 'FAILED'
invalid_msg = 'Special Leave cannot exceed '||
to_char(XXDLALA_SPECIAL_LEAVE_MAX_DAYS)||' calendar days.'
)
)
/************* EDUCATION LEAVE
**********************************************************/
IF (l_leave_name = 'Education Leave')
THEN
(
IF (PER_NATIONALITY <> 'QATARI')
THEN
(
duration = 'FAILED'
invalid_msg = 'Only Qataris are eligible for Education Leave'
)
v_duration = days_between(Date_End,Date_Start)+1
duration = to_char(v_duration)

IF (ASG_PROB_END_DATE > date_end)


THEN
(
duration = 'FAILED'
invalid_msg = 'Employee is under Probation'
)

)
/************* EMERGENCY LEAVE
**********************************************************/
IF (l_leave_name = 'Emergency Leave')
THEN
(
v_duration = days_between(Date_End,Date_Start)+1 -
GET_WEEKEND_DAYS(Date_start,Date_End)
duration = to_char(v_duration)
Tot_Leaves = v_duration +
GET_COMMITTED_LEAVE_DAYS_NO_WE(absence_attendance_type_id,p_year)
IF (Tot_Leaves > XXDLALA_EMERGENCY_LEAVE_MAX_DAYS)
THEN
(
duration = 'FAILED'
invalid_msg = 'Emergency Leave cannot exceed '||
to_char(XXDLALA_EMERGENCY_LEAVE_MAX_DAYS)||' working days.'
)
)
/********* TRAINING LEAVE
****************************************************************/
IF (l_leave_name = 'Training Leave')
THEN
(
v_duration = days_between(Date_End,Date_Start)+1
duration = to_char(v_duration)

IF (ASG_PROB_END_DATE > date_end)


THEN
(
duration = 'FAILED'
invalid_msg = 'Employee is under Probation'
)
)
/********* PENALTY, TRAINING, ABSENT (Leave without information), UNPAID LEAVES
**********/
IF (l_leave_name = 'Penalty Leave' OR l_leave_name = 'Absent' OR
l_leave_name = 'Unpaid Leave')
THEN
(
v_duration = DAYS_BETWEEN(date_end,date_start) + 1
duration = to_char(v_duration)
)
/
***********************************************************************************
*******/
) /* End Inner Else */
) /* End Outer Else */

/* Return Section */
RETURN duration,invalid_msg

You might also like