How to calculate annual leave - please advise
Hi,
I need your advise please..
here is the detail:::
The employee contract can be definite (with expiry date) or indefinite (open without expiry date).
The employee contract will always have date of join
if the contract is definite then employee will have 30 days every year where the year is the period between the date of join and
+365 days and the renewal is the same (from the renewal date and +365)
if the contract is indefinite then employee will have 30 days every year where the year is the period between the date of join
it's every 365 days so the contract has not renewal but the employee will have 30 days annually.
for example, if indefinite and date of join is 1 April 2010 then every period from 1 April until 30 March will have 30 days for
the employee
I want to calculate the leaves for the employee without having to keep a renew table so it will be calculated based on the leave
date and the first date of join.
so the data will be just one leave table with from and to indicating the leave period for every leave and the result will be
1 April - 31 March - [Total Taken Leaves] - [Total Remaining Leaves]
hope
I explained it well...
I think I understand what you're saying. Try out the code below to see if it works for you.
I know you mentioned possibly have a table with leave_from and leave_to as the structure for how you would keep track of each employee's leave days, but I would simplify it to just EmployeeID and the LeaveDate, which is what I did below.
If you choose to go with a range, then you need to start dealing with only business days in your leave range calculations.
-- CREATE SOME DATA
IF OBJECT_ID('tempdb..#Employee', 'U') IS NOT NULL DROP TABLE #Employee;
CREATE TABLE #Employee (
EmployeeID int NOT NULL
,FullName varchar(30) NOT NULL
,JoinDate date NOT NULL
,EndDate date NULL
IF OBJECT_ID('tempdb..#EmployeeDaysOnLeave', 'U') IS NOT NULL DROP TABLE #EmployeeDaysOnLeave;
CREATE TABLE #EmployeeDaysOnLeave (
EmployeeID int NOT NULL
,LeaveDate date NOT NULL
INSERT #Employee
SELECT A.*
FROM (SELECT * FROM #Employee WHERE 1=2
UNION ALL SELECT 1, 'Joe', '01/01/2014', NULL
UNION ALL SELECT 2, 'Bob', '07/01/2014', '01/01/2015'
UNION ALL SELECT 3, 'Eve', '10/15/2007', NULL
UNION ALL SELECT 4, 'Ila', '09/08/2000', NULL
UNION ALL SELECT 5, 'Oto', '07/01/2014', '01/01/2017'
UNION ALL SELECT 6, 'Pop', '01/01/2013', '06/01/2013' -- Already let go
) A
INSERT #EmployeeDaysOnLeave
SELECT A.*
FROM (SELECT * FROM #EmployeeDaysOnLeave WHERE 1=2
UNION ALL SELECT 1, '01/30/2013'
UNION ALL SELECT 1, '01/31/2013'
UNION ALL SELECT 1, '02/01/2013'
UNION ALL SELECT 1, '02/04/2013'
UNION ALL SELECT 1, '04/15/2013'
UNION ALL SELECT 1, '04/16/2013'
UNION ALL SELECT 1, '04/17/2013'
UNION ALL SELECT 1, '04/18/2013'
UNION ALL SELECT 1, '04/19/2013'
UNION ALL SELECT 1, '01/30/2014'
UNION ALL SELECT 1, '01/31/2014'
UNION ALL SELECT 1, '02/03/2014'
UNION ALL SELECT 1, '02/04/2014'
UNION ALL SELECT 1, '04/14/2014'
UNION ALL SELECT 1, '04/15/2014'
UNION ALL SELECT 1, '04/16/2014'
UNION ALL SELECT 1, '04/17/2014'
UNION ALL SELECT 1, '04/18/2014'
UNION ALL SELECT 2, '07/21/2014'
UNION ALL SELECT 2, '07/22/2014'
UNION ALL SELECT 2, '07/23/2014'
UNION ALL SELECT 2, '07/24/2014'
UNION ALL SELECT 2, '07/25/2014'
UNION ALL SELECT 2, '07/28/2014'
UNION ALL SELECT 2, '07/29/2014'
UNION ALL SELECT 2, '07/30/2014'
) A
-- NOTE: I'm throwing all these calculations into a quick temp table, but you may want to put this logic into a view or table function
IF OBJECT_ID('tempdb..#EmployeeLeaveCalculations', 'U') IS NOT NULL DROP TABLE #EmployeeLeaveCalculations;
DECLARE @DaysPerYear int
,@CurrentDate date
SELECT @DaysPerYear = 30
,@CurrentDate = CONVERT(date, GETDATE())
SELECT A.EmployeeID
,A.FullName
,A.JoinDate
,A.EndDate
,A.LeaveCalculationStartDate
,A.LeaveCalculationEndDate
,CASE WHEN A.LeaveCalculationEndDate < A.LeaveCalculationStartDate -- Ignore if they are no longer with the company
THEN 0
ELSE CASE WHEN DATEDIFF(DAY, A.LeaveCalculationStartDate, A.LeaveCalculationEndDate) < 365
THEN @DaysPerYear * DATEDIFF(DAY, A.LeaveCalculationStartDate, A.LeaveCalculationEndDate) / 365.0
ELSE @DaysPerYear * 1.0
END
END as LeaveDaysEntitledTo
,CASE WHEN DATEDIFF(DAY, A.LeaveCalculationStartDate, A.LeaveCalculationEndDate) = 0 OR -- Avoid divide by zero
A.LeaveCalculationEndDate < A.LeaveCalculationStartDate -- Ignore if they are no longer with the company
THEN 0
ELSE ROUND(DATEDIFF(DAY, A.LeaveCalculationStartDate, @CurrentDate) * 1.0 /
DATEDIFF(DAY, A.LeaveCalculationStartDate, A.LeaveCalculationEndDate)* 1.0 *
CASE WHEN DATEDIFF(DAY, A.LeaveCalculationStartDate, A.LeaveCalculationEndDate) < 365
THEN @DaysPerYear * DATEDIFF(DAY, A.LeaveCalculationStartDate, A.LeaveCalculationEndDate) / 365.0
ELSE @DaysPerYear * 1.0
END
, 1)
END as CurrentLeaveDaysAccrued
INTO #EmployeeLeaveCalculations
FROM (
SELECT EmployeeID
,FullName
,JoinDate
,ISNULL(EndDate, '12/12/9999') as EndDate
-- If the Month/Date of their JoinDate is less than the current Month/Date,
-- then we reset the leave start date to this year
-- else it will be the previous year
,CASE WHEN CONVERT(int, RIGHT(CONVERT(char(8), JoinDate, 112),4)) <= CONVERT(int, RIGHT(CONVERT(char(8), @CurrentDate, 112),4))
THEN CONVERT(date, CONVERT(char(4), YEAR(@CurrentDate)) + RIGHT(CONVERT(char(8), JoinDate, 112),4))
ELSE CONVERT(date, CONVERT(char(4), YEAR(@CurrentDate)-1) + RIGHT(CONVERT(char(8), JoinDate, 112),4))
END as LeaveCalculationStartDate
,CASE WHEN EndDate IS NOT NULL AND EndDate < DATEADD(YEAR,1,JoinDate)
THEN EndDate
WHEN CONVERT(int, RIGHT(CONVERT(char(8), JoinDate, 112),4)) <= CONVERT(int, RIGHT(CONVERT(char(8), @CurrentDate, 112),4))
THEN CONVERT(date, CONVERT(char(4), YEAR(@CurrentDate)+1) + RIGHT(CONVERT(char(8), JoinDate, 112),4))
ELSE CONVERT(date, CONVERT(char(4), YEAR(@CurrentDate)) + RIGHT(CONVERT(char(8), JoinDate, 112),4))
END as LeaveCalculationEndDate
FROM #Employee
) A
SELECT X.*
,Y.TotalLeaveDaysTaken
,X.CurrentLeaveDaysAccrued - Y.TotalLeaveDaysTaken as CurrentLeaveDaysBalance
,X.LeaveDaysEntitledTo - Y.TotalLeaveDaysTaken as TotalRemainingLeaveDays
FROM #EmployeeLeaveCalculations X
JOIN (
-- Get the total leave days taken from the given Employee's leave calculation start date
SELECT A.EmployeeID
,SUM(CASE WHEN B.EmployeeID IS NOT NULL THEN 1 ELSE 0 END) as TotalLeaveDaysTaken
FROM #EmployeeLeaveCalculations A
LEFT JOIN #EmployeeDaysOnLeave B
ON A.EmployeeID = B.EmployeeID
AND A.LeaveCalculationStartDate <= B.LeaveDate
GROUP BY A.EmployeeID
) Y
ON X.EmployeeID = Y.EmployeeID
Similar Messages
-
Need to wipe hard drive to restore to previous date from time machine back up. Unclear how to do this. Please advise or provide link to this procedure on website. Thanks.
See Pondini's TM FAQs for starters.
-
Hello again, I'm still learning about my imac so here I go with latest question- I've installed word 2011 and would like to know how to email the document I have just written straight to a recipient but can't seem to find how to do this. Please advise in simple terms
Also how do I save to a file.
Thank you clever world!!To save you file click the disc icon in the tool bar or file save as:
To email the Word document to someone compose a new message and click the paper clip to attach the Document. -
How to remove annual leave accrued in time management
Hi all.
I have question in Time management. When I run some employees, their annual leave increase 15 days every day. So at the end of the year
their annual leave become more than 10000 days. How I want to stop this.What I want annual leave for this staff is 15 days every year and
the max carry forward can is 15 days per year. Can you help me.I'm too new in time management let alone negative time management.
ThanksI believe you are referring to Absence Quota Accrual right?
If it is, table T556C (SM30) has all the customizing for counting and deduction rule. For the counting rule, check if you haven't set a multiplier.
But more important, is to check V_T559L -> Selection Rules. I believe you have a bad customizing for the ACcrual Period. If you want to accrue yearly based, I would recommend maintaining IT0041 with the date employee entered company and use it on the field Rel. to Date Type.
Of course, you can accrue as per calendar year as well.
Please check that and get back in case you still have issues.
Regards,
Bentow. -
How to craete 'annual leave 1/2day-AM' in ESS leave request
Hi ,
I have created 2001- subtype 670 : "annual leave 1/2day-AM".
I wanted to see "annual leave 1/2day-AM" in the ESS leave request list down box ( already we have few ) ... please let me know what are the steps i need to follow ...
thanks,
sunithaHi,
Your ABAPer will be the best person to let you know the table name or some experts here who have come across this situation will guide you. Also check where other types of leaves are populated in SAP and your new value is there or not.
Thanks,
Preetham -
I have just purchased the new iPad with the camera connection kit and want to be able to view my photos full screen and not import them. Can this be done and how? Please advise. Thank you.
When connecting the Camera Connection Kit to a camera or SD card all you see are the thumbnails of the photos. I suggest you review those, select the photos you might want to see full screen, then import them to your iPad. After viewing them you can always delete them if you no longer want them on your iPad.
I also suggest Keeping the photos on your camera or SD card until you import the to your computer and back them up to at least one other location. -
i'm using Adobe CS we reinstall windows then we need to activate program by internet but it can't then we try to activate by phone it also can't no longer support by phone how we can do ? please advise
Tomzeer please see Activation server shut down for Creative Suite 2, Acrobat 7, and Macromedia products where this topic has been discussed.
-
I had submitted my app to apple for approval. My app got rejected as
PayPal has been used as payment method. in-app purchase method was
suggested by apple. My app charges yearly subscription from users. In-App
purchase does not support this type of payment process ( or, I could not
get to it).
Please allow me to use paypal or guide me on how can I charge yearly
subscription from users using in-app purchase payment method.You're not talking to anybody from Apple here.
We're all just users like you.
But I can tell you without reservation that PayPal cannot be used in an iOS app. -
I need help sending my iphoto book for printing. When it is uploading, the bar reaches approx. 3/4 of the way, then an "error message" comes up suggesting I cancel or retry. I've retried several times but it still won't go. What can I do?
set the wake-on lan on the main computer
The laptop's too far away from the router to be connected by ethernet. It's all wifi.
No separate server app on the laptop, it's all samba
The files are on a windows laptop and a hard drive hooked up to the windows laptop. The windows share server is pants, so I'd need some sort of third party server running. Maybe you weren't suggesting to use Samba to connect to the windows share though?
I'm glad that you've all understood my ramblings and taken and interest, thanks The way I see it, I can't be the only netbook user these days looking for this kind of convenience, and I certainly won't be once chrome and moblin hit the market.
Last edited by saft (2010-03-18 20:38:08) -
How to view CEO annual leave on self selvice
I have a requirement for the CEO HR personnel to be able to view his annual leave details on self service.
But as he is not her surbordinate, he doesnt appear in the list of 'My Employee'
information she can view. Can someone please advise the best way to meet this requirement?
How can we allow the HR personnel to view his entitlement etc details on self
service.Hi
What is the need to see Annual leave only through self service. I think HR should use professional screen.
Just change the security profile of responsibility and check if this works. Not sure though.
Thanks
Avinash -
i am trying to purchase many songs at one time. i have added all songs to wish list , now to purchase it will only let me do one at a time please advise how i can purchase more than one at a time
There used to be a 'buy all' button on the wish list screen but for some reason that has been removed from the current version of iTunes so you will need to buy each item individually. You can try leaving feedback for Apple and maybe it'll be added back in a future update : http://www.apple.com/feedback/itunesapp.html
-
How to display balance days for annual leave in payslip report
hi all,
cn sm1 let me know how i can display the leave balance days of each employee on their payslip.
please let me know the tables where i can find the info of the employee annual leave days balance.
The leave defined is decreasing.
Plz i need your assistance gurus.
All comments are welcomed!No one out there to response buddies?
-
Firefox hangs on opening requiring force quit I have snow leopard Mac It even hangs when I try safe mode. I need to know how to remove all traces of firefox on my mac so I can reinstall. I have tried terminal as advised on firefox webpage. Please advise me
== This happened ==
Every time Firefox opened
== I tried to update firefox add-ons ==
== User Agent ==
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7Try a new profile. See [[Recovering important data from an old profile]]
-
I have installed Adobe Creative Cloud for teams CC Packages which says that Acrobat XI Pro is installed. Your support page says it does not install Acrobat and I have to look in the Extensions folder for an MSI file. I have run a number of searches and cannot find the Acrobat extension folder please advise how can I get these applications to load onto my computer?
Also I now administer the teams and have accepted the invitation to I received to be a team member and download the apps. The admin page shows that I have been sent an invitation but does not show my account as "ACtive" unlike my other team members. I tried to use the link in the invite to accept it become active but the link displayed an error saying I had already accepted the invite... why is no account not active?
Finally what other product downloads in Creative Cloud do not actually download as part of the Creative cloud Packager for downloading the apps? e.g. acrobat and what else?My apologies Eadeszoo I believe our support agents are unavailable on January 1.
Are you able to copy the contents of the DVD to your computer? Are you receiving any particular error messages when you are trying to install? Finally which operating system are you using? -
My wife and I both have iCloud accounts and would like to share photo's etc. Can any one please advise if this is possible and how to do it?
I have a Macbook-pro and Ipad, my wife has a much loved ipad.It's all described in iCloud Help here: http://help.apple.com/icloud/#mmc0cd7e99
Maybe you are looking for
-
I used to be able to choose from all folders when bookmarking a site. I was able to click on 'Choose' and all folder would drop down. After a firefox update yesterday, only 5 folders show up, along with the 'Choose' option. When I click on 'Choose' i
-
Error code 39 - CD/DVD drive not working properly
Satellite C55D-5170 came with Win 8 and the first automatic software update upgraded it to Win 8.1. I believe this is the first time I have tried to access the DVD drive but I had successfully used the flash drive. The DVD drive is not recognized.
-
Uploading Multiple files in One-Click!!!
Hi All, I have got nearly about 900 PDF files in my file server which need to be uploaded to the KM CONTENT Repository. what is the best methodology to upload all these file in to the repository in <u><b>one click.</b></u> Is it possible to achieve t
-
IPhone 5 sound on video is almost nonexistent
The iPhone 5 takes great video, but the sound is almost not there at all. Husband still has his iPhone 4 and the sound is fine. Any thoughts? I looked at settings and the sound is all the way up, and it isn't a problem hearing messages, etc.
-
[SOLVED]Keyboard layout changed.
Hi i did a major upgrade yesterday, having waited to do an upgrade for a few weeks because of wonky nvidia drivers i finally managed to Syu yesterday and upgraded 133 packages. Everything works fine it seems apart from one thing i noticed this mornin