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); } }
public static List <TimeCardView> LinesToTimeCardView(IEnumerable <Line> tcLines) { List <TimeCardView> view = new List <TimeCardView>(); int i = 0; double regular = 0; double overtime = 0; double doubletime = 0; PunchTypes pType = new PunchTypes(); foreach (Line line in tcLines) { regular = 0; overtime = 0; doubletime = 0; switch (line.PayType.Description) { case "Regular": regular += line.SplitEnd.Subtract(line.SplitStart).TotalMinutes; break; case "Overtime": overtime += line.SplitEnd.Subtract(line.SplitStart).TotalMinutes; break; case "Doubletime": doubletime += line.SplitEnd.Subtract(line.SplitStart).TotalMinutes; break; } switch (line.Punch.PunchTypeID) { case 1: pType = PunchTypes.REGULAR; break; case 2: pType = PunchTypes.SICK; break; case 3: pType = PunchTypes.VACATION; break; case 4: pType = PunchTypes.HOLIDAY; break; } var single = new TimeCardView() { lineNum = i, Date = line.SplitStart.Date, In = line.SplitStart, Out = line.SplitEnd, Entry = line.SplitEnd.Subtract(line.SplitStart), Regular = regular, Overtime = overtime, Doubletime = doubletime, PunchType = pType, PunchID = line.PunchID, isRapid = false }; single.generateText(); view.Add(single); } return(view); }
public static List<TimeCardView> LinesToTimeCardView(IEnumerable<Line> tcLines) { List<TimeCardView> view = new List<TimeCardView>(); int i = 0; double regular = 0; double overtime = 0; double doubletime = 0; PunchTypes pType = new PunchTypes(); foreach (Line line in tcLines) { regular = 0; overtime = 0; doubletime = 0; switch (line.PayType.Description) { case "Regular": regular += line.SplitEnd.Subtract(line.SplitStart).TotalMinutes; break; case "Overtime": overtime += line.SplitEnd.Subtract(line.SplitStart).TotalMinutes; break; case "Doubletime": doubletime += line.SplitEnd.Subtract(line.SplitStart).TotalMinutes; break; } switch (line.Punch.PunchTypeID) { case 1: pType = PunchTypes.REGULAR; break; case 2: pType = PunchTypes.SICK; break; case 3: pType = PunchTypes.VACATION; break; case 4: pType = PunchTypes.HOLIDAY; break; } var single = new TimeCardView() { lineNum = i, Date = line.SplitStart.Date, In = line.SplitStart, Out = line.SplitEnd, Entry = line.SplitEnd.Subtract(line.SplitStart), Regular = regular, Overtime = overtime, Doubletime = doubletime, PunchType = pType, PunchID = line.PunchID, isRapid = false }; single.generateText(); view.Add(single); } return view; }