You are on page 1of 5

/*

FORMULA NAME: TEMPLATE_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 */
Alias EMP_HIRE_DATE as hire_date
INPUTS ARE days_or_hours(text),
date_start (date),
date_end (date),
time_start (text),
time_end (text),
C_TYPE_DESC (text),
C_REASON_DESC (text),
element_type_id (text),
ABS_ATTENDANCE_REASON_ID
/* default values */
DEFAULT FOR element_type_id is '1'
DEFAULT FOR days_or_hours IS 'D'
DEFAULT FOR time_start IS '08:00'
DEFAULT FOR time_end IS '16: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 EMP_HIRE_DATE IS '0001/01/01 00:00:00' (DATE)
DEFAULT FOR sysdate IS '0001/01/01 00:00:00' (DATE)
DEFAULT FOR FLOATING_ASG_FYTD is 0
/* database items */
DEFAULT FOR asg_start_time IS '08:00'
DEFAULT FOR asg_end_time IS '16:00'
DEFAULT FOR asg_pos_start_time IS '08:00'
DEFAULT FOR asg_pos_end_time IS '16:00'
DEFAULT FOR PER_SEX is ' '
DEFAULT FOR FLOATING_ASG_FYTD is 0
/* local variables */
error_or_warning = ' '
invalid_msg = ' '
duration = '0'
number_of_days = 0
first_day_hours = 0
last_day_hours = 0
hire_year = to_number(substr(to_char(hire_date),1,4))
sys_year = to_number(substr(to_char(sysdate),1,4))
F_year = to_char(sysdate,'DD/MM/YYYY')
/* Defaults Section */
/* default values for working day, these are only used if no
working conditions can be found */
begin_day = '08:00'
end_day = '16: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
(
/**********************************************************/
Days = DAYS_BETWEEN(date_end,date_start)+1
Fri_Days = roundup(days_between(add_days(date_end,1) , next_day(add_days(date_
start,-1),'FRIDAY'))/7)
Sat_Days = roundup(days_between(add_days(date_end,1),next_day(add_days(date_st
art,-1),'SATURDAY'))/7)
abs_days = Days - Fri_Days - Sat_Days
duration = to_char(abs_days)
/********************** Hajj Vacation *************************/

if element_type_id ='147' and to_num(duration) > 30 then


(
duration = 'FAILED'
invalid_msg = 'Hajj Vacation cannot be more than 30 days'
)
if element_type_id ='147' and (sys_year - Hire_year) <5 then
(
duration = 'FAILED'
invalid_msg = 'Hajj Vacation Not Allowed'
)
/********************** Parent Day Vacation ********************/
/*
if PER_SEX = 'Male' and element_type_id ='148' and to_num(duration) >2 then
(
duration = 'FAILED'
invalid_msg = Per_sex
)
if element_type_id ='148' and PER_SEX = 'Female' then
(
duration = 'FAILED'
invalid_msg = 'This Vacation for Male only '
)
*/
/********************** Maternity Vacation *********************/
IF element_type_id ='162' THEN
(
IF PER_SEX = 'Female' and to_num(duration) >90 THEN
(
duration = 'FAILED'
invalid_msg = 'Maternity Vacation Cannot be more than 90 days'
)
ELSE IF PER_SEX = 'Male' THEN
(
duration = 'FAILED'
invalid_msg = 'Maternity Vacation for Female only '
)
)
/********************** Baby Care Vacation *********************/
/*
if PER_SEX = 'Female' then
(
if element_type_id ='142' and to_num(duration) >90 then
(
duration = 'FAILED'
invalid_msg = 'Maternity Vacation Cannot be more that 90 days'
)
)
if element_type_id ='142' and PER_SEX = 'Male' then
(
duration = 'FAILED'
invalid_msg = 'Maternity Vacation for Female only '
)
*/
/********************** Casual Vacation ************************/
/*
if element_type_id = '144' and ABS_ATTENDANCE_REASON_ID = '61' and to_num(durat
ion) > 2 then
(
duration = 'FAILED'
)
*/
/********************** Floating Vacation **********************/
if element_type_id ='166' and to_num(duration) > 2 then
(
duration = 'FAILED'
invalid_msg = 'Floating Vacation cannot be more than 2 days'
)
/* if element_type_id ='166' and F_year = '29/03/2008' then
(
duration = 'FAILED'
invalid_msg = 'Floating Vacation Not Allowed'
)*/
/***************************************************************/

)
/* use of error messages:
if to_num(duration) = 0 then
(
duration = 'FAILED'
invalid_msg = 'HR_ABSENCE_CANNOT_BE_ZERO'
)
*/
)

return duration, invalid_msg

You might also like