Sunteți pe pagina 1din 5

Hazem.elrefai@gmail.

com

How to Use calendar for saving Holydays and Calculating Leaves


Durations

I use the Calendar Function to save the holidays that will affect the absences durations and may also
affect the overtime rates.
What I do is:
1. I save the Holidays like National Day on the calendar
2. use a SQL Function in my BG_ABSENCE_DUATION Formula that will check the duration based on
these saved Holidays.

Part I : Creating the Event


3. Go to: Work structure >> Calendar Events >> Events & Coverage >> Enter & Maintain Events
4. Click on Create Buttons
Hazem.elrefai@gmail.com

5. Fill the fields:


a. Name
b. Start Date
c. End Date (the same as the start date if the event is one day)
d. Type = Public Holiday
e. Select All Business Groups Check box if you need it to be valid for all business groups.
6. Click Next

7. Click Next Again


8. Click Next Again and Again and you will get the confirmation that you saved
Hazem.elrefai@gmail.com

9. Now you can search for it, delete it, or update it.
Hazem.elrefai@gmail.com

Part II : Validation the absence duration in BG_ABSENCE_DUARTION_FORMULA


1. Add the following SQL Function to Database, this function calculate the duration of leaves after
subtracting the holidays and Weekends, if in your case you do not subtract the weekends, then
just remove the lines related to this.

FUNCTION xx_count_working_days (starting_date DATE, total_days NUMBER)


RETURN NUMBER
IS
day_num NUMBER := 0;
count_days NUMBER := 0;
l_date DATE;
l_read_result NUMBER := 0;
BEGIN
-- find day of the week
day_num := TO_CHAR (starting_date, 'D');
l_date := TO_CHAR (starting_date, 'DD-MON-YYYY');

-- loop until end of absence


FOR i IN 1 .. (total_days)
LOOP
-- if neither Saturday nor Friday then add to counter
IF ((day_num <> 6) AND (day_num <> 7))
THEN
l_read_result := 0;

BEGIN
SELECT DISTINCT 1
INTO l_read_result
FROM per_calendar_entries
WHERE (TO_CHAR (l_date, 'DD-MON-YYYY') BETWEEN
start_date AND end_date);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
count_days := count_days + 1;
END;
END IF;

l_date := l_date + 1;
-- if Sunday then start again
IF day_num = 7
THEN
day_num := 1;
ELSE
-- else next day
day_num := day_num + 1;
END IF;
END LOOP;

RETURN count_days;
END xx_count_working_days;
Hazem.elrefai@gmail.com

2. Register the function in the Application

3. Add the following code to the BG_ABSENCE_DURATION Formula to calculate the duration after
subtracting the Holidays and Week Ends.

duration_days = XX_COUNT_WORKING_DAYS(DATE_START, DAYS_BETWEEN (DATE_END,


DATE_START)+1)

duration = to_char(duration_days)

Hazem.elrefai@gmail.com

S-ar putea să vă placă și