コード例 #1
0
        /**
         * Test function
         **/

        public HttpResponseMessage RebuildLines(string employeeId, string timecardDate = null)
        {
            using (var db = new TimeClockContext())
            {
                var employee = db.Employees.SingleOrDefault(e => e.EmployeeID == employeeId);

                if (employee == null)
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }

                PayPeriod payperiod = PayPeriodTools.LookupPayPeriod(db, employee.DepartmentID);

                if (timecardDate != null)
                {
                    payperiod = PayPeriodTools.LookupPayPeriod(db, employee.DepartmentID, DateTime.Parse(timecardDate));
                }

                var timecard = employee.Timecards.SingleOrDefault(tc => tc.PayPeriod == payperiod.Start);

                employee.rebuildTimecardLines(db, timecard);

                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
        }
コード例 #2
0
        public double minutsWorkedDate(TimeClockContext db, DateTime date)
        {
            PayPeriod currentPP = PayPeriodTools.LookupPayPeriod(db, DepartmentID, date);
            Timecard  tc        = db.Timecards.SingleOrDefault(t => t.PayPeriod.Equals(currentPP.Start) && t.EmployeeID.Equals(EmployeeID));

            //Get all lines for this timecard
            var allLines = db.Lines.Where(l => l.TimecardID == tc.TimecardID).ToList();

            //Need to remove the lines that don't match our logic, LINQ wasn't a fan of this so just pull them out one at a time.
            List <Line> lines = new List <Line>();

            foreach (Line line in allLines)
            {
                if (line.SplitStart.Subtract(date).TotalMinutes >= 0 && line.SplitEnd.Subtract(date.AddDays(1)).TotalMinutes <= 0)
                {
                    lines.Add(line);
                }
            }

            double minutesWorked = 0;

            foreach (Line line in lines)
            {
                minutesWorked += line.getDuration().TotalMinutes;
            }

            return(minutesWorked);
        }
コード例 #3
0
        public ActionResult Timecard(string id)
        {
            using (var db = new TimeClockContext())
            {
                int lineNumberCounter         = 1;
                List <TimeCardView> timecard  = new List <TimeCardView>();
                PayPeriod           payPeriod = PayPeriodTools.LookupPayPeriod(db, 1);

                var empTC = db.Timecards.SingleOrDefault(t => t.EmployeeID == id && t.PayPeriod == payPeriod.Start);

                var lines = db.Lines.Where(l => l.TimecardID == empTC.TimecardID);

                lines.OrderBy(l => l.SplitStart);

                foreach (Line line in lines)
                {
                    int last = timecard.Count - 1;
                    if (last > 0 && timecard[last].PunchID == line.PunchID)
                    {
                        timecard[last].Out = line.SplitEnd;
                        if (line.PayType.Description == "Overtime")
                        {
                            timecard[last].Overtime = line.SplitEnd.Subtract(line.SplitStart).TotalHours;
                        }
                        else if (line.PayType.Description == "Regular")
                        {
                            timecard[last].Regular = line.SplitEnd.Subtract(line.SplitStart).TotalHours;
                        }
                        else
                        {
                            ;
                        }

                        timecard[last].updateEntry();
                    }

                    // Otherwise we create a new line and add it to the timecard.
                    else
                    {
                        TimeCardView temp = new TimeCardView(lineNumberCounter, line.SplitStart.Date, line.SplitStart, line.SplitEnd, line.PunchID);
                        if (line.PayType.Description == "Regular")
                        {
                            temp.Regular = line.SplitStart.Subtract(line.SplitEnd).TotalHours;
                        }
                        else if (line.PayType.Description == "Overtime")
                        {
                            temp.Overtime = line.SplitStart.Subtract(line.SplitEnd).TotalHours;
                        }
                        else
                        {
                            ;// What should we do if it is neither of the two?
                        }
                        timecard.Add(temp);
                    }
                }

                return(PartialView(timecard));
            }
        }
コード例 #4
0
        public int isWorking(TimeClockContext db)
        {
            PayPeriod payPeriod = PayPeriodTools.LookupPayPeriod(db, 1);

            var empPunches = db.Punches.Where(p => p.EmployeeID == EmployeeID && p.InTime > payPeriod.Start && p.InTime < payPeriod.End && p.OutTime == null);

            if (empPunches.Count(p => p.OutTime == null) != 0)
            {
                var lastPunch = empPunches.OrderBy(p => p.InTime).AsEnumerable().Last();

                if (DateTime.Now.Subtract(lastPunch.InTime) < TimeSpan.FromHours(24))
                {
                    return(lastPunch.PunchID);
                }
            }
            return(-1);
        }
コード例 #5
0
        public ActionResult PunchGrid(string EID, PayPeriod pay = null)
        {
            using (var db = new TimeClockContext())
            {
                if (pay == null)
                {
                    pay = PayPeriodTools.LookupPayPeriod(db, 1);
                }

                // How are we suppose to handle punches that extend over the end of a payperiod?
                //
                // Get all punches from p payperiod - into a list
                List <Punch> punches = db.Punches.Where(p => p.EmployeeID == EID && pay.Start < p.InTime && p.InTime < pay.End).ToList();


                // return partial view
                return(PartialView("PunchData", punches));
            }
        }
コード例 #6
0
        //Should return identical to time card lines
        public HttpResponseMessage <PunchResponse> GetTimeCardDetails(string empId, int tcId = -1)
        {
            if (tcId == -1)
            {
                var emp       = db.Employees.SingleOrDefault(e => e.EmployeeID == empId);
                var payPeriod = PayPeriodTools.LookupPayPeriod(db, emp.DepartmentID);
                var tcLookup  = emp.Timecards.SingleOrDefault(tc => tc.PayPeriod == payPeriod.Start);
                tcId = tcLookup.TimecardID;
            }

            Timecard curTimeCard = db.Timecards.SingleOrDefault(tc => tc.TimecardID == tcId);

            var timeCardData = db.Lines.Where(l => l.TimecardID == curTimeCard.TimecardID).OrderBy(l => l.SplitStart).ToList();

            var lines = TimeCardView.LinesToTimeCardView(timeCardData);

            PunchResponse ret = new PunchResponse()
            {
                lines = lines
            };

            return(new HttpResponseMessage <PunchResponse>(ret));
        }
コード例 #7
0
        public HttpResponseMessage <PunchResponse> Punch(PunchRequest request)
        {
            Employee emp = db.Employees.FirstOrDefault(e => e.EmployeeID.Equals(request.ID));

            if (!emp.Pin.Equals(request.pin)) // the pin didn't match don't do anything
            {
                PunchResponse response = new PunchResponse()
                {
                    isSuccess    = false,
                    pinError     = "Pin and user did not match.",
                    lines        = null,
                    generalError = null
                };

                return(new HttpResponseMessage <PunchResponse>(response));
            }
            else
            {
                var payPeriod   = PayPeriodTools.LookupPayPeriod(db, emp.DepartmentID);
                var curTimeCard = emp.Timecards.SingleOrDefault(tc => tc.PayPeriod == payPeriod.Start);

                PunchResponse retVal = new PunchResponse()
                {
                    isSuccess    = true,
                    pinError     = "",
                    generalError = null
                };

                if (request.closesPunch == -1)  // Create a new punch in the DB
                {
                    Punch temp = new Punch()
                    {
                        EmployeeID   = emp.EmployeeID,
                        InTime       = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0),
                        OutTime      = null,
                        DepartmentID = emp.DepartmentID,
                        PunchTypeID  = Constants.DEFAULT_PUNCH_TYPE // Make this equal to the Regular punch type.
                    };

                    db.Punches.Add(temp);
                    db.SaveChanges();

                    var timeCardData = TimeCardView.LinesToTimeCardView(db.Lines.Where(l => l.TimecardID == curTimeCard.TimecardID).OrderBy(l => l.SplitStart));
                    // We add the last line to just display the information, letting the user know that we register the punch in
                    timeCardData.Add(new TimeCardView()
                    {
                        DateText       = DateTime.Now.ToString(@"MM\/dd\/yy"),
                        InText         = temp.InTime.ToString(@"hh\:mm"),
                        OutText        = "",
                        RegularText    = "",
                        OvertimeText   = "",
                        DoubletimeText = ""
                    });

                    retVal.lines = timeCardData;
                }
                else // We need to close the last punch and make lines -- Make it split the lines over the payperiod seed
                {
                    // Set the ending time of the punch
                    Punch currentPunch = db.Punches.First(p => p.PunchID == request.closesPunch);
                    currentPunch.OutTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);

                    var timeCardData = db.Lines.Where(l => l.TimecardID == curTimeCard.TimecardID).OrderBy(l => l.SplitStart).ToList();

                    retVal.lines = TimeCardView.LinesToTimeCardView(timeCardData);

                    if (currentPunch.OutTime.Value.Subtract(currentPunch.InTime).TotalMinutes < 1) // punch was shorter than a minut.
                    {
                        db.Punches.Remove(currentPunch);
                        retVal.lines.Add(new TimeCardView() // Make the last line show, but mark is as rapid since it won't get put in the DB
                        {
                            DateText       = currentPunch.InTime.ToString(@"MM\/dd\/yy"),
                            InText         = currentPunch.InTime.ToString(@"hh\:mm"),
                            OutText        = currentPunch.OutTime.Value.ToString(@"hh\:mm"),
                            RegularText    = "00:00",
                            OvertimeText   = "00:00",
                            DoubletimeText = "00:00",
                            isRapid        = true
                        });
                    }
                    else // Punch was longer than a minut, we add it to the DB.
                    {
                        Calculations.addLines(db, currentPunch);
                    }

                    db.SaveChanges();
                }

                return(new HttpResponseMessage <PunchResponse>(retVal));
            }
        }
コード例 #8
0
        public HttpResponseMessage <PunchResponse> Punch(PunchRequest request)
        {
            using (var db = new TimeClockContext())
            {
                /******************************************************************************    TODO ITEM    *********************************/
                //This is where we need to insert the new punch for the employee
                //If it is an out punch, we should recalculate their timecard lines.
                Employee emp = db.Employees.FirstOrDefault(e => e.EmployeeID.Equals(request.ID));

                if (!emp.Pin.Equals(request.pin))
                {
                    PunchResponse response = new PunchResponse()
                    {
                        isSuccess    = false,
                        pinError     = "Pin and user did not match.",
                        lines        = null,
                        generalError = null
                    };

                    return(new HttpResponseMessage <PunchResponse>(response));
                }
                else
                {
                    var payPeriod   = PayPeriodTools.LookupPayPeriod(db, emp.DepartmentID);
                    var curTimeCard = emp.Timecards.SingleOrDefault(tc => tc.PayPeriod == payPeriod.Start);

                    PunchResponse retVal = new PunchResponse()
                    {
                        isSuccess    = true,
                        pinError     = "",
                        generalError = null
                    };


                    if (request.closesPunch == -1)  // Create a new punch in the DB
                    {
                        Punch temp = new Punch()
                        {
                            EmployeeID   = emp.EmployeeID,
                            InTime       = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0),
                            OutTime      = null,
                            DepartmentID = emp.DepartmentID,
                            PunchTypeID  = Constants.DEFAULT_PUNCH_TYPE // Make this equal to the Regular punch type.
                                                                        //OutTime = null;
                        };

                        db.Punches.Add(temp);
                        db.SaveChanges();

                        var timeCardData = new List <TimeCardView>();
                        timeCardData.Add(new TimeCardView()
                        {
                            DateText       = DateTime.Now.ToString(@"MM\/dd\/yy"),
                            InText         = temp.InTime.ToString(@"hh\:mm"),
                            OutText        = "",
                            RegularText    = "",
                            OvertimeText   = "",
                            DoubletimeText = ""
                        });

                        retVal.lines = timeCardData;
                    }
                    else // We need to close the last punch and make lines -- Make it split the lines over the payperiod seed
                    {
                        // Set the ending time of the punch
                        Punch currentPunch = db.Punches.First(p => p.PunchID == request.closesPunch);
                        currentPunch.OutTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);

                        if (currentPunch.OutTime.Value.Subtract(currentPunch.InTime).TotalMinutes < 1)
                        {
                            db.Punches.Remove(currentPunch);
                        }

                        db.SaveChanges();


                        Calculations.addLines(db, currentPunch);

                        var timeCardData = db.Lines.Where(l => l.TimecardID == curTimeCard.TimecardID).OrderBy(l => l.SplitStart).ToList();

                        retVal.lines = TimeCardView.LinesToTimeCardView(timeCardData);
                    }

                    /*
                     * PunchResponse retVal = new PunchResponse()
                     * {
                     *  isSuccess = true,
                     *  pinError = "",
                     *  lines = TimeCardView.LinesToTimeCardView(timeCardData),
                     *  generalError = null
                     * };
                     */
                    return(new HttpResponseMessage <PunchResponse>(retVal));
                }
            }
        }