Beispiel #1
0
        /**Method to get list of Timesheet objects by employee id and week ending date.Queries the TimeSheet
         * table by employee id and WeekEnding date and returns List collection of Timesheet objects**/
        public List <TimeSheet> GetTimeSheetByWeek(int Banner_ID, List <string> dates)
        {
            List <TimeSheet> timesheets = new List <TimeSheet>();
            string           wEnd       = dates[0].Trim();
            var sheets = from tsheets in db.TimeSheets
                         where tsheets.Banner_ID == Banner_ID && tsheets.WeekEnding == wEnd
                         orderby tsheets.Id ascending
                         select tsheets;
            var count = sheets.Count();

            Debug.WriteLine("TimeSheet count is: " + count.ToString() + "********************************************************************************************************************************");
            if (count == 0)
            {
                for (int i = 1; i < 8; i++)
                {
                    TimeSheet sheet = new TimeSheet
                    {
                        Id                     = this.GetMaxTimeSheetId() + 1,
                        WeekEnding             = dates[0].Trim(),
                        Date                   = dates[i].Trim(),
                        TimeIn                 = "",
                        OutForLunch            = "",
                        InFromLunch            = "",
                        TimeOut                = "",
                        LeaveId                = 0,
                        LeaveHours             = "",
                        AdditionalHours        = "",
                        TotalHoursWorked       = "",
                        Submitted              = "False",
                        AuthorizedBySupervisor = "False",
                        Banner_ID              = Banner_ID,
                        Note                   = ""
                    };
                    this.InsertTimeSheet(sheet);
                    timesheets.Add(sheet);
                }
            }
            else
            {
                foreach (TimeSheet sheet in sheets)
                {
                    timesheets.Add(sheet);
                }
            }
            return(timesheets);
        }
Beispiel #2
0
        //Method to update TimeSheet data in the TimeSheet data table
        public void UpdateTimeSheet(TimeSheet sheet)
        {
            TimeSheet tsheet = (from tsheets in db.TimeSheets
                                where tsheets.Id == sheet.Id
                                select tsheets).First();

            tsheet.Id                     = sheet.Id;
            tsheet.WeekEnding             = sheet.WeekEnding;
            tsheet.Date                   = sheet.Date;
            tsheet.TimeIn                 = sheet.TimeIn;
            tsheet.OutForLunch            = sheet.OutForLunch;
            tsheet.InFromLunch            = sheet.InFromLunch;
            tsheet.TimeOut                = sheet.TimeOut;
            tsheet.LeaveId                = sheet.LeaveId;
            tsheet.LeaveHours             = sheet.LeaveHours;
            tsheet.AdditionalHours        = sheet.AdditionalHours;
            tsheet.TotalHoursWorked       = tsheet.CalculateTotalHoursWorked(sheet);
            tsheet.Submitted              = sheet.Submitted;
            tsheet.AuthorizedBySupervisor = sheet.AuthorizedBySupervisor;
            tsheet.EmpId                  = sheet.EmpId;

            db.SaveChanges();
        }
Beispiel #3
0
 //Method to insert TimeSheet data into the TimeSheet data table
 public void InsertTimeSheet(TimeSheet sheet)
 {
     db.TimeSheets.Add(sheet);
     db.SaveChanges();
 }
Beispiel #4
0
        /**Calculates the total hours work for a day including additional hours**/
        public string CalculateWorkedHours(TimeSheet sheet)
        {
            try
            {
                string totalHours;
                int    hours   = 0;
                int    minutes = 0;
                if (!String.IsNullOrEmpty(sheet.TimeIn.Trim()) && !String.IsNullOrEmpty(sheet.OutForLunch.Trim()) && String.IsNullOrEmpty(sheet.InFromLunch.Trim()) && String.IsNullOrEmpty(sheet.TimeOut.Trim()))
                {
                    Debug.WriteLine("Calculating the first 2 punches");
                    DateTime tIn  = RoundToNearest(DateTime.Parse(sheet.TimeIn), TimeSpan.FromMinutes(15));;
                    DateTime lOut = RoundToNearest(DateTime.Parse(sheet.OutForLunch), TimeSpan.FromMinutes(15));
                    //used to view the incoming values
                    Debug.WriteLine("Clocked in at " + tIn + " in 2 Punches");
                    Debug.WriteLine("Clocked out for lunch at " + lOut + " in 2 Punches");

                    if (tIn > lOut)
                    {
                        totalHours = "Error";
                    }
                    else
                    {
                        int addHour   = 0;
                        int addMinute = 0;

                        /*Once the verification it the LeaveHours and AdditionalHours are added we can unblock the following code!*/
                        if (!String.IsNullOrEmpty(sheet.AdditionalHours.Trim()))
                        {
                            string AdditionalHours = sheet.AdditionalHours.ToString().Trim();
                            addHour   = Convert.ToInt16(AdditionalHours.Split(':')[0]);
                            addMinute = Convert.ToInt16(AdditionalHours.Split(':')[1]);
                        }

                        TimeSpan hoursWorked = lOut.Subtract(tIn);
                        int      hour        = Convert.ToInt16(Math.Truncate(hoursWorked.TotalHours + addHour)); // + leaveHour + addHour;
                        int      minute      = Convert.ToInt16(hoursWorked.Minutes + addMinute);                 // + leaveMinute + addMinute;
                        totalHours = hour.ToString() + ":" + minute.ToString();
                        Debug.WriteLine(hoursWorked + "************* " + hoursWorked.TotalHours + "************************* " + hour + " ************* " + minute + " add time " + AdditionalHours);
                    }
                    Debug.WriteLine("TotalHours from the first 2 punches :" + totalHours);
                    //return totalHours;
                }

                else if (!String.IsNullOrEmpty(sheet.TimeIn.Trim()) && !String.IsNullOrEmpty(sheet.OutForLunch.Trim()) && !String.IsNullOrEmpty(sheet.InFromLunch.Trim()) && !String.IsNullOrEmpty(sheet.TimeOut.Trim()))
                {
                    Debug.WriteLine("Calculating all times");
                    DateTime tIn  = RoundToNearest(DateTime.Parse(sheet.TimeIn), TimeSpan.FromMinutes(15));;
                    DateTime lOut = RoundToNearest(DateTime.Parse(sheet.OutForLunch), TimeSpan.FromMinutes(15));
                    DateTime lIn  = RoundToNearest(DateTime.Parse(sheet.InFromLunch), TimeSpan.FromMinutes(15));
                    DateTime tOut = RoundToNearest(DateTime.Parse(sheet.TimeOut), TimeSpan.FromMinutes(15));
                    //used to view the incoming values
                    Debug.WriteLine("Clocked in at " + tIn + " in 4 Punches");
                    Debug.WriteLine("Clocked out for lunch at " + lOut + " in 4 Punches");
                    Debug.WriteLine("Clocked in from lunch at " + lIn + " in 4 Punches");
                    Debug.WriteLine("Clocked out at " + tOut + " in 4 Punches");
                    if (tIn > lOut || lOut > lIn || lIn > tOut)
                    {
                        totalHours = "Error";
                    }
                    else
                    {
                        int addHour   = 0;
                        int addMinute = 0;

                        /*Once the verification it the LeaveHours and AdditionalHours are added we can unblock the following code!*/
                        if (!String.IsNullOrEmpty(sheet.AdditionalHours.Trim()))
                        {
                            string AdditionalHours = sheet.AdditionalHours.ToString().Trim();
                            addHour   = Convert.ToInt16(AdditionalHours.Split(':')[0]);
                            addMinute = Convert.ToInt16(AdditionalHours.Split(':')[1]);
                        }

                        TimeSpan hoursWorked = tOut.Subtract(tIn).Subtract(lIn.Subtract(lOut));
                        int      hour        = Convert.ToInt16(Math.Truncate(hoursWorked.TotalHours + addHour)); // + leaveHour + addHour;
                        int      minute      = Convert.ToInt16(hoursWorked.Minutes + addMinute);                 // + leaveMinute + addMinute;
                        Debug.WriteLine(hoursWorked + "************* " + hoursWorked.TotalHours + "************************* " + hour + " ************* " + minute + " add time " + AdditionalHours);
                        totalHours = hour.ToString() + ":" + minute.ToString();
                    }
                    //return totalHours;
                }

                else if (String.IsNullOrEmpty(sheet.TimeIn.Trim()) && String.IsNullOrEmpty(sheet.OutForLunch.Trim()) && String.IsNullOrEmpty(sheet.InFromLunch.Trim()) && String.IsNullOrEmpty(sheet.TimeOut.Trim()) && String.IsNullOrEmpty(sheet.AdditionalHours.Trim()) && String.IsNullOrEmpty(sheet.LeaveHours.Trim()))
                {
                    Debug.WriteLine("Skipping over empty day not filled out yet.");
                    totalHours = "NoTime";
                    //return totalHours;
                }

                else if (!String.IsNullOrEmpty(sheet.AdditionalHours.Trim()) && String.IsNullOrEmpty(sheet.TimeIn.Trim()) && String.IsNullOrEmpty(sheet.OutForLunch.Trim()) && String.IsNullOrEmpty(sheet.InFromLunch.Trim()) && String.IsNullOrEmpty(sheet.TimeOut.Trim()) && String.IsNullOrEmpty(sheet.LeaveHours.Trim()))
                {
                    Debug.WriteLine("if only additional hours are worked..");
                    totalHours = sheet.AdditionalHours.ToString().Trim();
                    //return totalHours;
                }

                else if (!String.IsNullOrEmpty(sheet.LeaveHours.Trim()) && String.IsNullOrEmpty(sheet.AdditionalHours.Trim()) && String.IsNullOrEmpty(sheet.TimeIn.Trim()) && String.IsNullOrEmpty(sheet.OutForLunch.Trim()) && String.IsNullOrEmpty(sheet.InFromLunch.Trim()) && String.IsNullOrEmpty(sheet.TimeOut.Trim()))
                {
                    Debug.WriteLine("if only leave hours are worked..");
                    totalHours = "NoTime";
                    //return totalHours;
                }

                else if (!String.IsNullOrEmpty(sheet.LeaveHours.Trim()) && !String.IsNullOrEmpty(sheet.AdditionalHours.Trim()) && String.IsNullOrEmpty(sheet.TimeIn.Trim()) && String.IsNullOrEmpty(sheet.OutForLunch.Trim()) && String.IsNullOrEmpty(sheet.InFromLunch.Trim()) && String.IsNullOrEmpty(sheet.TimeOut.Trim()))
                {
                    Debug.WriteLine("if both leave and addtional....");
                    totalHours = sheet.AdditionalHours.ToString().Trim();
                    //return totalHours;
                }

                else
                {
                    Debug.WriteLine("Sending 'Missing Punch' hours for the day because punches are missing. only gets called for 1 punch and 3 punches 999999999999");
                    totalHours = "Missing Punch";
                    //return totalHours;
                }

                Debug.WriteLine(totalHours + " in total Hours");
                if (totalHours.Equals("NoTime"))
                {
                    totalHours  = "0";
                    HoursWorked = totalHours;
                    return(totalHours);
                }
                else if (totalHours.Equals("Missing Punch"))
                {
                    totalHours  = "Missing Punch";
                    HoursWorked = totalHours;
                    return(totalHours);
                }

                else if (!totalHours.Equals("Error"))
                {
                    Debug.WriteLine("Passed the if");
                    hours   = Convert.ToInt16(totalHours.Split(':')[0]);
                    minutes = Convert.ToInt16(totalHours.Split(':')[1]);
                    if (minutes >= 60)
                    {
                        minutes = minutes - 60;
                        hours   = hours + 1;
                    }
                    totalHours  = hours + ":" + minutes;
                    HoursWorked = totalHours;
                    Debug.WriteLine("Running total: " + totalHours);
                    Debug.WriteLine("Running total by the hours: " + hours);
                    return(totalHours);
                }
                else
                {
                    Debug.WriteLine("Failed the if");
                    totalHours  = "Error";
                    HoursWorked = totalHours;
                    return(totalHours);
                }
            }
            catch (ArgumentException ae)
            {
                Debug.WriteLine(ae);
                return("");
            }
        }
Beispiel #5
0
        /**Method to update TimeSheet data in the TimeSheet data table**/
        public void UpdateTimeSheet(TimeSheet sheet)
        {
            WeeklyReport weeklyReport = new WeeklyReport();

            Debug.WriteLine("in database save 1");
            Debug.WriteLine("******************************************************************************************************** " + sheet.LeaveId);
            Debug.WriteLine("With sheet id: " + sheet.Id + "]");

            string timeIn      = "";
            string outForLunch = "";
            string inFromLunch = "";
            string timeOut     = "";

            if (!String.IsNullOrEmpty(sheet.TimeIn.Trim()))
            {
                timeIn = sheet.TimeIn;
            }
            else
            {
                timeIn = "";
            }
            if (!String.IsNullOrEmpty(sheet.OutForLunch.Trim()))
            {
                outForLunch = sheet.OutForLunch;
            }
            else
            {
                outForLunch = "";
            }
            if (!String.IsNullOrEmpty(sheet.InFromLunch.Trim()))
            {
                inFromLunch = sheet.InFromLunch;
            }
            else
            {
                inFromLunch = "";
            }
            if (!String.IsNullOrEmpty(sheet.TimeOut.Trim()))
            {
                timeOut = sheet.TimeOut;
            }
            else
            {
                timeOut = "";
            }

            TimeSheet tsheet = (from tsheets in db.TimeSheets
                                where tsheets.Id == sheet.Id
                                select tsheets).Single();

            Debug.WriteLine("The sheet is: " + sheet.Note + "]");
            tsheet.Id                     = sheet.Id;
            tsheet.WeekEnding             = sheet.WeekEnding;
            tsheet.Date                   = sheet.Date;
            tsheet.TimeIn                 = timeIn;
            tsheet.OutForLunch            = outForLunch;
            tsheet.InFromLunch            = inFromLunch;
            tsheet.TimeOut                = timeOut;
            tsheet.LeaveId                = sheet.LeaveId;
            tsheet.LeaveHours             = sheet.LeaveHours;
            tsheet.AdditionalHours        = sheet.AdditionalHours;
            tsheet.TotalHoursWorked       = tsheet.CalculateTotalHoursWorked(sheet);
            tsheet.Submitted              = sheet.Submitted;
            tsheet.AuthorizedBySupervisor = sheet.AuthorizedBySupervisor;
            tsheet.Banner_ID              = sheet.Banner_ID;
            tsheet.Note                   = sheet.Note;
            Debug.WriteLine("The tsheet is :" + sheet.LeaveId + "55555555555555]");

            db.SaveChanges();

            weeklyReport.getWeeklyReport(sheet.Banner_ID, sheet.WeekEnding.Trim());
        }