Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.94/5 (5 votes)
See more:
employee leave management system
employee can take 2 leaves in a month.if he is not taking leave then leave will be carry forward to next month.but after total 2 years these carry forward leaves can't be used.how can i calculate available leaves every month.
public bool CheckLeaveStatus(int empid, DateTime date)
    {
        bool temp = false;
        int totalleave = 0;
        string qry = "select joining from profile where profileid=@id";
        MySqlParameter idP = new MySqlParameter("@id", empid);
        DataRow dr = MySqlHelper.ExecuteDataRow(Common.GetConnectionString(), qry, idP);
        if (dr != null)
        {
            DateTime joiningdate = Convert.ToDateTime(dr["joining"]);
            int legaldate = joiningdate.Day;
            if (legaldate <= 15)
            {
                totalleave += 2;
            }
            else
            {
                totalleave += 0;
            }
            //TimeSpan t1 = date - joiningdate;
            int monthspassed = Common.MonthDifference(date, joiningdate);
            if (monthspassed > 3)//then he is allowd to take leave
            {
                int startmonth = joiningdate.Month + 1;
                int endmonth = date.Month;
                int monthdiffernce = endmonth - startmonth;
              /*here i am having problem how can i written logic for two years passed from joiningdate and after that every month again two leaves issued .in this previous leave is not taken care off and leave taken count from new logic because two years passed */
                if (monthdiffernce > 24)
                {
                    monthdiffernce = 24;
                }
                int leaves = (monthdiffernce) * 2;
                int allowedleaves = leaves + totalleave;
                int availablelaves = allowedleaves - LeaveTaken(empid);
                if (availablelaves > 0)
                {
                    temp = true;
                }
            }
            //DateTime previousdate = date.AddYears(-2);
        }
        return temp;
    }
 public int LeaveTaken(int empid)
    {
        try
        {
            int taken = 0;
            string qry = "select count(*) from leavestatus where empid=@id";
            MySqlParameter idP = new MySqlParameter("@id", empid);
            taken = Convert.ToInt32(MySqlHelper.ExecuteScalar(Common.GetConnectionString(), qry, idP));
            return taken;
        }
        catch
        {
            return 0;
        }
    }
    public void AddLeaves(int empid, DateTime date, string status)
    {
        if (status == "L")
        {
            string qry = "insert into leavestatus(empid,takenon)values(@empid,@takenon)";
            MySqlParameter idP = new MySqlParameter("@empid", empid);
            MySqlParameter takenonP = new MySqlParameter("@takenon", date);
            MySqlParameter[] p = { idP, takenonP };
            MySqlHelper.ExecuteNonQuery(Common.GetConnectionString(), qry, p);
        }
    }


What I have tried:

how can i done this. pls tell me
Posted
Updated 16-Sep-16 3:21am
v2
Comments
Suvendu Shekhar Giri 16-Sep-16 2:26am    
What have you tried so far?
buffedcheesy 16-Sep-16 2:41am    
It would be helpful to tell us, what kind of system you're working with, if you use a sql server or a local db etc.
pankajgarg1986 16-Sep-16 2:51am    
i am using sql server with asp .net c#

Start by working out the employee length of employment in whole months.
Take the minimum of that and 24 - this is the totalMonths - and work out the start date from that and the current date.
Look back in your records up to the start date, and count the number of leaves. Double the totalMonths and subtract the number he took.

That's just a rough guess, based on "good for the employee" practices. Your company may have more restrictive practices, and if so, you will need to include those. You may well have to include some kind of "look ahead" to allow the employee to use leave in the summer that he will accrue in subsequent months - this is pretty normal in the real world, but may be unnecessary for this exercise.
 
Share this answer
 
Comments
pankajgarg1986 16-Sep-16 4:51am    
how can i calculate two years passed and employee can use not taken leave up to 2 years after that all leaves lapsed not carry forward.
OriginalGriff 16-Sep-16 4:56am    
Sorry? do you want to try explaining that in more detail?
Remember that we can't see your screen, access your HDD, or read your mind.
pankajgarg1986 16-Sep-16 5:22am    
every month employee can take 2 leaves and in a month if he takes less than 2 leaves suppose 1 then 1 leave is remaining this leave is valid for two years.he can take this leaves + 2 leaves in next months and so on. but these carry forward leaves can't be used after two years passed.
OriginalGriff 16-Sep-16 5:34am    
OK - and how are you storing these?
pankajgarg1986 16-Sep-16 5:38am    
i don't have idea pls suggest
This code:
if (legaldate <= 15)
{
    totalleave += 2;
}
else
{
    totalleave += 0;
}

can be simplified to
if (legaldate <= 15)
{
    totalleave += 2;
}

because
totalleave += 0;

does nothing.

If you have a problem in your code, ask a question.

If your problem is:
Maciej Los wrote:
Your issue is about how to write proper algorithm?

I recommend to learn some analyze methods, Dijkstra Top-Down method is a good start.
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[^]
https://en.wikipedia.org/wiki/Structured_programming[^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[^]
 
Share this answer
 
v2

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