Click here to Skip to main content
15,891,621 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Good Day
I am designing data base for leave management
if suppose i am taking a leave then should i save the leave balance on every request and all the leave details.
in separate table or
Should i calculate them leave balance dynamically and other details.

Which is the best approach should i save the leave details like balance how many leave are remaining how many are taken in a separate table

or
should i calculate them dynamically and show .
Posted
Comments
Ajith K Gatty 5-Jun-14 8:52am    
Hi Surajemo,
follow the suggestion of Peter Leow.
If you are considering real world scenarios(Employee leave Management) then every year this value gets refreshed.That is say you have total 30 days leave in a year, and you haven't used any of it.Again in next year you have again 30 days leave and u didnt consume it then you will be still having 30 days leave instead of 60 days.30(a years total leave) days amount will be given to you.At any conditions you cant have more than fixed leave count(Decided by company). So dont worry about so many past years record.

Both are good approach. But I would prefer store it in database so that you can view the balance leaves offline also without going online every time.
 
Share this answer
 
Comments
surajemo 5-Jun-14 7:43am    
thank u for replying
if we store the balance in the table then the balance information won't be accurate so when on tries to apply leave if he sees that he has balance he will apply and the leave will go successfully and another problem would be when do i run the service and will store the leave balance would it run every minute ?
these are the problems i am facing
if i do it dynamically then everything will be fine it will be slow .
Leave balance is derivable and dependent on leave entitlement and leave applied, so it should be calculated dynamically by code, it has no place in the database. Just like your age, you need store date of birth but not age as age is changing and derivable from date of birth.
 
Share this answer
 
Comments
surajemo 5-Jun-14 8:22am    
thank you for replying
Your are right but .
What if we have many employee's and data is there of many years.
So when i right the query to see if he has balance it will take a lot of time.
That is why i was considering of saving the leave balance other details related to it .
Please correct me if i am going wrong.
Peter Leow 6-Jun-14 8:04am    
Sorry for the late reply, I do not seem to receive any notification of new messages lately, wonder why? To your question, I thought the validity of leave is for one or 2 years, correct me if I am wrong. Unused leaves that are expired should not be involved in the leave balance calculation. They should be marked with some flag like 'expired' and be archived off or may be moving them to another table. In this way, users will always access valid leaves when applying for leave, but give them an option to view "leave history" the data of which is now residing in another table. My 2-cent worth.
surajemo 8-Jun-14 15:29pm    
its ok no problem
Saving leave balance is it a good idea .
hi Suraj

Leave Management sound complex in the beginning, but if you look closer you will notice it is not. Now Leave management should be treated the same as accounting transaction are treated. in a Year let us say the Employer gives an employee 30 days. Now these 30 days are not given instantly they get earned every month and for 12 months it form 30 days. So now in your table you should have fields like this


Create Table Employee_Leave_Balance
(
Employee_Leave_Balance_id int Identity(1,1) primary key,
User_id int ,--This is for the Employee , because he us a user in the system we use user_id,
Number_of_days decimal --This is because , there can be half day application so you need to cater
Leave_Type_ID int ,
Add_date datetime ,
Leave_Status int
)

Now the above table can contain data like this


Emploee_Leave_Balance_id user_id Number_of_days Add_date
1 44 2.4
2 44 2.4
3 44 2.4
4 34 2.4
5 44 2.4
6 33 2.4
6 44 -4


Now the above example tells you that user_id 44 accumulated days and later on he used 4 Days now when you sum the number of days remaining you will get his latest balance. Here you can have a view that will retrieve the total balance based on the user_id.

This is just my idea, you can just take what is good from it and make your own leave management module better
 
Share this answer
 
Comments
surajemo 9-Jun-14 3:56am    
Thank you for replying
but the view which will give the balance .would it be faster to retrieve records .
pankajgarg1986 16-Sep-16 2:12am    
how can i done this if total balance is valid for 2 years after that it can't be added to leave balance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900