public void TimeCardRules_CalculateWeeklyOvertime_OneWeekOverTwoPayPeriods() { string suffix = "26"; DateTime startDate = DateTime.Parse("2001-02-01"); //This will create a pay period that splits a work week. Employee emp = EmployeeT.CreateEmployee(suffix); PayPeriod payP1 = PayPeriodT.CreateTwoWeekPayPeriodIfNotExists(startDate); PayPeriod payP2 = PayPeriodT.CreateTwoWeekPayPeriodIfNotExists(startDate.AddDays(14)); PayPeriods.RefreshCache(); Prefs.UpdateInt(PrefName.TimeCardOvertimeFirstDayOfWeek, 0); TimeCardRules.RefreshCache(); long clockEvent1 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(10).AddHours(6), startDate.AddDays(10).AddHours(17), 0); long clockEvent2 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(11).AddHours(6), startDate.AddDays(11).AddHours(17), 0); long clockEvent3 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(12).AddHours(6), startDate.AddDays(12).AddHours(17), 0); //new pay period long clockEvent4 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(14).AddHours(6), startDate.AddDays(14).AddHours(17), 0); TimeCardRules.CalculateWeeklyOvertime(emp, payP1.DateStart, payP1.DateStop); TimeCardRules.CalculateWeeklyOvertime(emp, payP2.DateStart, payP2.DateStop); //Validate List <TimeAdjust> resultList = TimeAdjusts.Refresh(emp.EmployeeNum, startDate, startDate.AddDays(28)); Assert.IsFalse(resultList.Count < 1); TimeAdjust result = resultList[0]; Assert.AreEqual(TimeSpan.FromHours(-4), result.RegHours); Assert.AreEqual(TimeSpan.FromHours(4), result.OTimeHours); }
public void TimeCardRules_CalculateWeeklyOvertime_ForDifferentClinicsRealData() { string suffix = "66"; DateTime startDate = DateTime.Parse("2016-05-09"); //This will create a pay period that splits a work week. Employee emp = EmployeeT.CreateEmployee(suffix); PayPeriod payP1 = PayPeriodT.CreateTwoWeekPayPeriodIfNotExists(startDate); PayPeriods.RefreshCache(); Prefs.UpdateInt(PrefName.TimeCardOvertimeFirstDayOfWeek, 0); TimeCardRules.RefreshCache(); //Each of these are 11 hour days. Should have 4 hours of OT with clinic 3 in the second pay period and 11 hours for clinic 4. //Week 1 - 40.4 hours long clockEvent1 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(0).AddHours(6), startDate.AddDays(0).AddHours(6 + 8), 0); //Mon long clockEvent2 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(1).AddHours(6), startDate.AddDays(1).AddHours(6 + 8), 0); //Tue long clockEvent3 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(2).AddHours(6), startDate.AddDays(2).AddHours(6 + 8.76), 0, 0.06); //Wed long clockEvent4 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(3).AddHours(6), startDate.AddDays(3).AddHours(6 + 8.72), 0, 0.73); //Thurs long clockEvent5 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(4).AddHours(6), startDate.AddDays(4).AddHours(6 + 8.12), 0, 0.41); //Fri //Week 2 - 41.23 hours long clockEvent6 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(7).AddHours(6), startDate.AddDays(7).AddHours(6 + 8.79), 0, 0.4); //Mon long clockEvent7 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(8).AddHours(6), startDate.AddDays(8).AddHours(6 + 8.85), 0, 0.38); //Tue long clockEvent8 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(9).AddHours(6), startDate.AddDays(9).AddHours(6 + 7.78), 0, 0.29); //Wed long clockEvent9 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(10).AddHours(6), startDate.AddDays(10).AddHours(6 + 8.88), 0, 0.02); //Thurs long clockEvent10 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(11).AddHours(6), startDate.AddDays(11).AddHours(6 + 8.59), 0, 0.57); //Fri TimeCardRules.CalculateWeeklyOvertime(emp, payP1.DateStart, payP1.DateStop); //Validate List <TimeAdjust> listAdjusts = TimeAdjusts.GetValidList(emp.EmployeeNum, startDate, startDate.AddDays(28)).OrderBy(x => x.OTimeHours).ToList(); Assert.AreEqual(2, listAdjusts.Count); Assert.AreEqual(TimeSpan.FromHours(-0.4), listAdjusts[0].RegHours); Assert.AreEqual(TimeSpan.FromHours(0.4), listAdjusts[0].OTimeHours); Assert.AreEqual(TimeSpan.FromHours(-1.23), listAdjusts[1].RegHours); Assert.AreEqual(TimeSpan.FromHours(1.23), listAdjusts[1].OTimeHours); }
private static IEnumerable <PayPeriod> BreakoutPaySchedule(Salary salary, BenefitPackage benefitPackage) { int payPeriodsPerYear = (int)salary.Interval; decimal typicalDeductions = (benefitPackage.NetCost / payPeriodsPerYear).TruncateToTwoDecimals(); var periods = Enumerable.Range(1, payPeriodsPerYear - 1) .Select(index => new PayPeriod() { Period = index, GrossPay = salary.PerPeriod, Deductions = typicalDeductions, }).ToList(); var lastPeriod = new PayPeriod { Period = payPeriodsPerYear, GrossPay = salary.Yearly - periods.Sum(x => x.GrossPay), Deductions = benefitPackage.NetCost - periods.Sum(x => x.Deductions) }; periods.Add(lastPeriod); return(periods); }
public void TimeCardRules_CalculateWeeklyOvertime_OneWeekOverTwoPayPeriodsForDifferentClinicPreferences() { string suffix = "64"; DateTime startDate = DateTime.Parse("2001-02-01"); //This will create a pay period that splits a work week. Employee emp = EmployeeT.CreateEmployee(suffix); PayPeriod payP1 = PayPeriodT.CreateTwoWeekPayPeriodIfNotExists(startDate); PayPeriod payP2 = PayPeriodT.CreateTwoWeekPayPeriodIfNotExists(startDate.AddDays(14)); PayPeriods.RefreshCache(); Prefs.UpdateInt(PrefName.TimeCardOvertimeFirstDayOfWeek, 0); TimeCardRules.RefreshCache(); //Each of these are 11 hour days. Should have 4 hours of OT with clinic 3 in the second pay period and 11 hours for clinic 4. long clockEvent1 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(10).AddHours(6), startDate.AddDays(10).AddHours(17), 0); //Sun long clockEvent2 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(11).AddHours(6), startDate.AddDays(11).AddHours(17), 1); //Mon long clockEvent3 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(12).AddHours(6), startDate.AddDays(12).AddHours(17), 2); //Tue //new pay period long clockEvent4 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(14).AddHours(6), startDate.AddDays(14).AddHours(17), 3); //Wed long clockEvent5 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(15).AddHours(6), startDate.AddDays(15).AddHours(17), 4); //Thurs TimeCardRules.CalculateWeeklyOvertime(emp, payP1.DateStart, payP1.DateStop); TimeCardRules.CalculateWeeklyOvertime(emp, payP2.DateStart, payP2.DateStop); //Validate List <TimeAdjust> listAdjusts = TimeAdjusts.GetValidList(emp.EmployeeNum, startDate, startDate.AddDays(28)).OrderBy(x => x.OTimeHours).ToList(); Assert.AreEqual(2, listAdjusts.Count); Assert.AreEqual(TimeSpan.FromHours(-4), listAdjusts[0].RegHours); Assert.AreEqual(3, listAdjusts[0].ClinicNum); Assert.AreEqual(TimeSpan.FromHours(4), listAdjusts[0].OTimeHours); Assert.AreEqual(TimeSpan.FromHours(-11), listAdjusts[1].RegHours); Assert.AreEqual(4, listAdjusts[1].ClinicNum); Assert.AreEqual(TimeSpan.FromHours(11), listAdjusts[1].OTimeHours); }
/** * 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)); } }
///<summary>Inserts one PayPeriod into the database. Provides option to use the existing priKey.</summary> internal static long Insert(PayPeriod payPeriod,bool useExistingPK) { if(!useExistingPK && PrefC.RandomKeys) { payPeriod.PayPeriodNum=ReplicationServers.GetKey("payperiod","PayPeriodNum"); } string command="INSERT INTO payperiod ("; if(useExistingPK || PrefC.RandomKeys) { command+="PayPeriodNum,"; } command+="DateStart,DateStop,DatePaycheck) VALUES("; if(useExistingPK || PrefC.RandomKeys) { command+=POut.Long(payPeriod.PayPeriodNum)+","; } command+= POut.Date (payPeriod.DateStart)+"," + POut.Date (payPeriod.DateStop)+"," + POut.Date (payPeriod.DatePaycheck)+")"; if(useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { payPeriod.PayPeriodNum=Db.NonQ(command,true); } return payPeriod.PayPeriodNum; }
public static void ReCalculatePeriod() { using (var db = new RentBikeEntities()) { var contracts = db.Contracts.Where(c => c.CONTRACT_STATUS == true).ToList(); foreach (var contract in contracts) { List <PayPeriod> lstPay = db.PayPeriods.Where(c => c.CONTRACT_ID == contract.ID).ToList(); int div = lstPay.Count % 3; if (div > 0) { div = 3 - div; PayPeriod lastPay = lstPay.LastOrDefault(); for (int i = 1; i <= div; i++) { PayPeriod pp = new PayPeriod(); pp.CONTRACT_ID = contract.ID; pp.PAY_DATE = lastPay.PAY_DATE.AddDays(i * 10); pp.AMOUNT_PER_PERIOD = lastPay.AMOUNT_PER_PERIOD; pp.STATUS = true; pp.ACTUAL_PAY = 0; db.PayPeriods.Add(pp); } } } db.SaveChanges(); } }
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); }
public void TimeCardRules_CalculateWeeklyOvertime_ForDifferentClinics() { string suffix = "62"; DateTime startDate = DateTime.Parse("2001-01-01"); Employee emp = EmployeeT.CreateEmployee(suffix); PayPeriod payP1 = PayPeriodT.CreateTwoWeekPayPeriodIfNotExists(startDate); PayPeriods.RefreshCache(); Prefs.UpdateInt(PrefName.TimeCardOvertimeFirstDayOfWeek, 0); TimeCardRules.RefreshCache(); //Each of these are 11 hour days. Should have 4 hours of OT with clinic 3 and 11 hours OT with clinic 4 the end of the pay period. long clockEvent1 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(0).AddHours(6), startDate.AddDays(0).AddHours(17), 0); long clockEvent2 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(1).AddHours(6), startDate.AddDays(1).AddHours(17), 1); long clockEvent3 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(2).AddHours(6), startDate.AddDays(2).AddHours(17), 2); long clockEvent4 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(3).AddHours(6), startDate.AddDays(3).AddHours(17), 3); long clockEvent5 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(4).AddHours(6), startDate.AddDays(4).AddHours(17), 4); TimeCardRules.CalculateWeeklyOvertime(emp, payP1.DateStart, payP1.DateStop); //Validate List <TimeAdjust> listAdjusts = TimeAdjusts.GetValidList(emp.EmployeeNum, startDate, startDate.AddDays(5)).OrderBy(x => x.OTimeHours).ToList(); Assert.AreEqual(2, listAdjusts.Count); Assert.AreEqual(TimeSpan.FromHours(-4), listAdjusts[0].RegHours); Assert.AreEqual(3, listAdjusts[0].ClinicNum); Assert.AreEqual(TimeSpan.FromHours(4), listAdjusts[0].OTimeHours); Assert.AreEqual(TimeSpan.FromHours(-11), listAdjusts[1].RegHours); Assert.AreEqual(4, listAdjusts[1].ClinicNum); Assert.AreEqual(TimeSpan.FromHours(11), listAdjusts[1].OTimeHours); }
// GET: LeaveApplication/CreateLeaveForm public ActionResult CreateLeaveList(DateTime start, DateTime end, _leaveType leaveType) { // Try to fetch Leaveapplication from DB if it exists LeaveApplicationViewModel applicationVM = new LeaveApplicationViewModel(); List <TimeRecord> newTimeRecords = new List <TimeRecord>(); ViewBag.LeaveType = LeaveApplication.GetLeaveTypeItems(); for (int i = 0; i <= (end - start).Days; i++) { // Fetch each timerecord in DB if it exists DateTime currentDate = start.AddDays(i); var newTimeRecord = new TimeRecord(currentDate.Date); newTimeRecord.SetAttendence(null, null, 0); newTimeRecord.UserID = User.Identity.Name; newTimeRecord.LeaveType = leaveType; newTimeRecord.LeaveTime = (leaveType == 0) ? 0 : 7.5; PayPeriod.SetPublicHoliday(newTimeRecord); if (!newTimeRecord.IsHoliday) { newTimeRecords.Add(newTimeRecord); } } applicationVM.TimeRecords = newTimeRecords; if (applicationVM.TimeRecords.Count == 0) { return(Content("No working days were found.")); } return(PartialView(@"~/Views/LeaveApplication/_LeaveList.cshtml", applicationVM)); }
// GET: Year // POST: Year public ActionResult SelectYear(int?year) { TimeSheetContainer model = new TimeSheetContainer(); model.PeriodList = PayPeriod.GetPeriodItems((year == null) ? DateTime.Now.Year : year.Value); return(PartialView("_SelectYear", model)); }
public void PayMonthPeriod_ValidMonth_31Days() { var target = new PayPeriod(3); string result = target.PayMonthPeriod; Assert.Equal("01 March to 31 March", result); }
public void PayMonthPeriod_ValidMonth_30Days() { var target = new PayPeriod(9); string result = target.PayMonthPeriod; Assert.Equal("01 September to 30 September", result); }
///<summary>Inserts one PayPeriod into the database. Returns the new priKey.</summary> public static long Insert(PayPeriod payPeriod) { if (DataConnection.DBtype == DatabaseType.Oracle) { payPeriod.PayPeriodNum = DbHelper.GetNextOracleKey("payperiod", "PayPeriodNum"); int loopcount = 0; while (loopcount < 100) { try { return(Insert(payPeriod, true)); } catch (Oracle.DataAccess.Client.OracleException ex) { if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")) { payPeriod.PayPeriodNum++; loopcount++; } else { throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return(Insert(payPeriod, false)); } }
///<summary>Inserts one PayPeriod into the database. Provides option to use the existing priKey.</summary> public static long Insert(PayPeriod payPeriod, bool useExistingPK) { if (!useExistingPK && PrefC.RandomKeys) { payPeriod.PayPeriodNum = ReplicationServers.GetKey("payperiod", "PayPeriodNum"); } string command = "INSERT INTO payperiod ("; if (useExistingPK || PrefC.RandomKeys) { command += "PayPeriodNum,"; } command += "DateStart,DateStop,DatePaycheck) VALUES("; if (useExistingPK || PrefC.RandomKeys) { command += POut.Long(payPeriod.PayPeriodNum) + ","; } command += POut.Date(payPeriod.DateStart) + "," + POut.Date(payPeriod.DateStop) + "," + POut.Date(payPeriod.DatePaycheck) + ")"; if (useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { payPeriod.PayPeriodNum = Db.NonQ(command, true); } return(payPeriod.PayPeriodNum); }
// POST: Year public ActionResult SelectYear(int year) { TimeSheetContainer model = new TimeSheetContainer(); model.PeriodList = PayPeriod.GetPeriodItems(year); return(PartialView("_SelectYear", model)); }
private void butAdd_Click(object sender, System.EventArgs e) { PayPeriod payPeriodCur = new PayPeriod(); if (PayPeriods.GetCount() == 0) { payPeriodCur.DateStart = DateTime.Today; } else { payPeriodCur.DateStart = PayPeriods.GetLast().DateStop.AddDays(1); } payPeriodCur.DateStop = payPeriodCur.DateStart.AddDays(13); //payPeriodCur.DateStop is inclusive, this is effectively a 14 day default pay period. This only affects default date of newly created pay periods. payPeriodCur.DatePaycheck = payPeriodCur.DateStop.AddDays(4); FormPayPeriodEdit FormP = new FormPayPeriodEdit(payPeriodCur); FormP.IsNew = true; FormP.ShowDialog(); if (FormP.DialogResult == DialogResult.Cancel) { return; } FillGrid(); changed = true; }
// GET: TimeSheet public async Task <ActionResult> Index(int message = 0) { ViewBag.Manager = UserRoleSetting.GetManagerItems(); int year = DateTime.Now.Year; int period = (int)(DateTime.Now - PayPeriod.FirstPayDayOfYear(year)).Days / 14 + 2; TimeSheetContainer model = await GetTimeSheetModel(year, period); model.YearList = PayPeriod.GetYearItems(); switch (message) { case 0: ViewBag.Message = ""; break; case 1: ViewBag.Message = "Please save timesheet before submit"; break; case 2: ViewBag.Message = "Timesheet approval email has been sent successfully"; break; case 3: ViewBag.Message = "Timesheet has been saved successfully"; break; default: ViewBag.Message = "no message"; break; } return(View(model)); }
/// <summary> /// Adjusts the date by a given payment period. /// </summary> /// <param name="date"></param> /// <param name="frequency"></param> /// <param name="period"></param> /// <returns>A DateTime with value of this instance adjusted by the frequency of period.</returns> public static DateTime AddPeriod(this DateTime date, int frequency, PayPeriod period) { switch (period) { case PayPeriod.Regular: date = date.AddDays(frequency); return(date); case PayPeriod.Weekly: date = date.AddDays(frequency * 7); return(date); case PayPeriod.Fortnightly: date = date.AddDays(frequency * 14); return(date); case PayPeriod.Monthly: date = date.AddMonths(frequency); return(date); case PayPeriod.Annually: date = date.AddYears(frequency); return(date); default: return(date); } }
///<summary>Inserts one PayPeriod into the database. Returns the new priKey.</summary> internal static long Insert(PayPeriod payPeriod) { if(DataConnection.DBtype==DatabaseType.Oracle) { payPeriod.PayPeriodNum=DbHelper.GetNextOracleKey("payperiod","PayPeriodNum"); int loopcount=0; while(loopcount<100){ try { return Insert(payPeriod,true); } catch(Oracle.DataAccess.Client.OracleException ex){ if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){ payPeriod.PayPeriodNum++; loopcount++; } else{ throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return Insert(payPeriod,false); } }
/// <summary>Returns existing payperiod if it exists, otherwise inserts and returns a new payperiod. Throws exception if payperiod overlaps existing payperiod.</summary> public static PayPeriod CreateTwoWeekPayPeriodIfNotExists(DateTime start) { PayPeriod ppNew = new PayPeriod(); ppNew.DateStart = start; ppNew.DateStop = start.AddDays(13); ppNew.DatePaycheck = start.AddDays(16); //check for identical or overlapping pay periods PayPeriods.RefreshCache(); foreach (PayPeriod ppInDb in PayPeriods.GetDeepCopy()) { if (ppInDb.DateStart == ppNew.DateStart && ppInDb.DateStop == ppNew.DateStop && ppInDb.DatePaycheck == ppNew.DatePaycheck) { //identical pay period already exists. return(ppInDb); } //if(pp.DateStart == payP.DateStart && pp.DateStop == payP.DateStop && pp.DatePaycheck != payP.DatePaycheck) { // //identical pay period already exists, just with a different pay check date. // //This is a seperate check because it may be important in the future. // continue; //} if (ppInDb.DateStop > ppNew.DateStart && ppInDb.DateStart < ppNew.DateStop) { //pay periods overlap throw new Exception("Error inserting pay period. New Pay period overlaps existing pay period.\r\n"); } } PayPeriods.Insert(ppNew); return(ppNew); }
///<summary></summary> public static void Insert(PayPeriod pp) { if (PrefB.RandomKeys) { pp.PayPeriodNum = MiscData.GetKey("payperiod", "PayPeriodNum"); } string command = "INSERT INTO payperiod ("; if (PrefB.RandomKeys) { command += "PayPeriodNum,"; } command += "DateStart,DateStop,DatePaycheck) VALUES("; if (PrefB.RandomKeys) { command += "'" + POut.PInt(pp.PayPeriodNum) + "', "; } command += POut.PDate(pp.DateStart) + ", " + POut.PDate(pp.DateStop) + ", " + POut.PDate(pp.DatePaycheck) + ")"; if (PrefB.RandomKeys) { General.NonQ(command); } else { pp.PayPeriodNum = General.NonQ(command, true); } }
///<summary>Inserts one PayPeriod into the database. Provides option to use the existing priKey. Doesn't use the cache.</summary> public static long InsertNoCache(PayPeriod payPeriod, bool useExistingPK) { bool isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys); string command = "INSERT INTO payperiod ("; if (!useExistingPK && isRandomKeys) { payPeriod.PayPeriodNum = ReplicationServers.GetKeyNoCache("payperiod", "PayPeriodNum"); } if (isRandomKeys || useExistingPK) { command += "PayPeriodNum,"; } command += "DateStart,DateStop,DatePaycheck) VALUES("; if (isRandomKeys || useExistingPK) { command += POut.Long(payPeriod.PayPeriodNum) + ","; } command += POut.Date(payPeriod.DateStart) + "," + POut.Date(payPeriod.DateStop) + "," + POut.Date(payPeriod.DatePaycheck) + ")"; if (useExistingPK || isRandomKeys) { Db.NonQ(command); } else { payPeriod.PayPeriodNum = Db.NonQ(command, true, "PayPeriodNum", "payPeriod"); } return(payPeriod.PayPeriodNum); }
private void butAdd_Click(object sender, System.EventArgs e) { PayPeriod payPeriodCur = new PayPeriod(); if (PayPeriods.List.Length == 0) { payPeriodCur.DateStart = DateTime.Today; } else { payPeriodCur.DateStart = PayPeriods.List[PayPeriods.List.Length - 1].DateStop.AddDays(1); } payPeriodCur.DateStop = payPeriodCur.DateStart.AddDays(14); payPeriodCur.DatePaycheck = payPeriodCur.DateStop.AddDays(4); FormPayPeriodEdit FormP = new FormPayPeriodEdit(payPeriodCur); FormP.IsNew = true; FormP.ShowDialog(); if (FormP.DialogResult == DialogResult.Cancel) { return; } FillGrid(); changed = true; }
public void PayMonthPeriod_ValidMonth_28Days() { var target = new PayPeriod(2); string result = target.PayMonthPeriod; Assert.Equal("01 February to 28 February", result); }
public void TimeCardRules_CalculateWeeklyOvertime_OneWeekWorkWeekStartsOnWednesday() { string suffix = "27"; DateTime startDate = DateTime.Parse("2001-01-01"); Employee emp = EmployeeT.CreateEmployee(suffix); PayPeriod payP1 = PayPeriodT.CreateTwoWeekPayPeriodIfNotExists(startDate); PayPeriods.RefreshCache(); Prefs.UpdateInt(PrefName.TimeCardOvertimeFirstDayOfWeek, 3); TimeCardRules.RefreshCache(); long clockEvent1 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(0).AddHours(6), startDate.AddDays(0).AddHours(17), 0); long clockEvent2 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(1).AddHours(6), startDate.AddDays(1).AddHours(17), 0); //new work week long clockEvent3 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(2).AddHours(6), startDate.AddDays(2).AddHours(17), 0); long clockEvent4 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(3).AddHours(6), startDate.AddDays(3).AddHours(17), 0); long clockEvent5 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(4).AddHours(6), startDate.AddDays(4).AddHours(17), 0); long clockEvent6 = ClockEventT.InsertWorkPeriod(emp.EmployeeNum, startDate.AddDays(5).AddHours(6), startDate.AddDays(5).AddHours(17), 0); TimeCardRules.CalculateWeeklyOvertime(emp, payP1.DateStart, payP1.DateStop); //Validate TimeAdjust result = TimeAdjusts.Refresh(emp.EmployeeNum, startDate, startDate.AddDays(28))[0]; Assert.AreEqual(TimeSpan.FromHours(-4), result.RegHours); Assert.AreEqual(TimeSpan.FromHours(4), result.OTimeHours); }
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 void PayPeriodTest() { var temp = PayPeriod.FindPayPeriod(new System.DateTime(2020, 7, 14)); Assert.AreEqual(FirstHalfOfMonth, temp); temp = PayPeriod.FindPayPeriod(new System.DateTime(2020, 7, 16)); Assert.AreEqual(SecondHalfOfMonth, temp); }
public void GeneratesPayslipWithCorrectData(Employee employee, PayPeriod payPeriod, Payslip expected) { var taxCalculator = new TaxCalculator(SetUpTestTaxTable()); var monthlyPayslipGenerator = new MonthlyPayslipGenerator(taxCalculator); var actual = monthlyPayslipGenerator.Generate(employee, payPeriod); Assert.Equal(expected.GrossIncome, actual.GrossIncome); }
public CreatePayPeriodForm(PayPeriod value) { InitializeComponent(); this.Text = "Create new pay period"; period = value; }
public static IEnumerable <object[]> TestData() { var employee = new Employee("John", "Doe", 60050, 9); var payPeriod = new PayPeriod(new DateTime(2020, 3, 1), new DateTime(2020, 3, 31)); var expected = new Payslip(employee, payPeriod, 5004.16667m, 0); yield return(new object[] { employee, payPeriod, expected }); }
public static IEnumerable <EmployeeReport> GenerateReport(IEnumerable <PaymentModel> payments) { Dictionary <int, Dictionary <PayPeriod, EmployeeReport> > employees = new Dictionary <int, Dictionary <PayPeriod, EmployeeReport> >(); foreach (var payment in payments) { if (!employees.ContainsKey(payment.EmployeeId)) { employees.Add(payment.EmployeeId, new Dictionary <PayPeriod, EmployeeReport>()); } var employeePaymentPeriods = employees[payment.EmployeeId]; var payPeriod = PayPeriod.FindPayPeriod(payment.Date); var salary = PayScale.Payments[payment.JobGroup] * payment.HoursWorked; if (!employeePaymentPeriods.ContainsKey(payPeriod)) { employeePaymentPeriods.Add(payPeriod, new EmployeeReport { EmployeeID = payment.EmployeeId, PayPeriod = payPeriod }); } employeePaymentPeriods[payPeriod].AmountPaid += salary; employeePaymentPeriods[payPeriod].HoursWorked += payment.HoursWorked; } var reports = new List <EmployeeReport>(); foreach (var employee in employees.Values) { foreach (var report in employee.Values.OrderBy(x => x.PayPeriod)) { if (report.HoursWorked > OVERTIME_HOURS) { var overTimeReport = new EmployeeReport { EmployeeID = payment.EmployeeId, PayPeriod = payPeriod }; overTimeReport.HoursWorked = report.HoursWorked - OVERTIME_HOURS; overTimeReport.AmountPaid = overTimeReport.HoursWorked * OVERTIME * PayScale.Payments[report.JobGroup]; reports.Add(overTimeReport); report.HoursWorked = (double)OVERTIME; report.AmountPaid = report.HoursWorked * PayScale.Payments[report.JobGroup]; reports.Add(report); } else { reports.Add(report); } } } return(reports); }
public void ThenTheyShouldHaveDetails(Table table) { foreach (var row in table.Rows) { var newPeriod = new PayPeriod(row["Name"], row["StartDate"], row["EndDate"]); _currentPayPeriods.ShouldContain(i=>i.PayPeriodName == newPeriod.PayPeriodName); _currentPayPeriods.ShouldContain(i => i.StartDate== newPeriod.StartDate); _currentPayPeriods.ShouldContain(i => i.EndDate == newPeriod.EndDate); } }
public void GivenIHaveANewSystemWithPayPeriods(Table table) { _payPeriodRepo = new PayPeriodRepository(); _payPeriodRepo.ClearAllPayPeriods(); foreach (var row in table.Rows) { var newPeriod = new PayPeriod(row["Name"], row["StartDate"], row["EndDate"]); _payPeriodRepo.AddNew(newPeriod); } }
///<summary>Converts a DataTable to a list of objects.</summary> public static List<PayPeriod> TableToList(DataTable table){ List<PayPeriod> retVal=new List<PayPeriod>(); PayPeriod payPeriod; for(int i=0;i<table.Rows.Count;i++) { payPeriod=new PayPeriod(); payPeriod.PayPeriodNum= PIn.Long (table.Rows[i]["PayPeriodNum"].ToString()); payPeriod.DateStart = PIn.Date (table.Rows[i]["DateStart"].ToString()); payPeriod.DateStop = PIn.Date (table.Rows[i]["DateStop"].ToString()); payPeriod.DatePaycheck= PIn.Date (table.Rows[i]["DatePaycheck"].ToString()); retVal.Add(payPeriod); } return retVal; }
public PayModel(PayPeriod period, object[] parameters) { if (parameters.Count() == 0) throw new ArgumentException("Must have parameter value."); switch (period) { case PayPeriod.Daily: if (parameters[0] is DayOfWeek) { var dayOfWeek = (DayOfWeek)parameters[0]; } else { throw new ArgumentException("Must have DayOfWeek parameter"); } break; default: throw new ArgumentException("Not valid period type."); } }
public static void CreatePayPeriod(RentBikeEntities db, int contractId, PayPeriod lastPeriod, bool bFirstCreate) { var contract = db.Contracts.FirstOrDefault(c => c.CONTRACT_STATUS == true && c.ID == contractId); if (contract != null) { int multipleFee; decimal increateFeeCar; decimal increateFeeEquip; decimal increateFeeOther; CalculatePeriodFee(db, contract, out multipleFee, out increateFeeCar, out increateFeeEquip, out increateFeeOther, bFirstCreate); CreateOneMorePayPeriod(db, contract, lastPeriod, multipleFee, increateFeeCar, increateFeeEquip, increateFeeOther, bFirstCreate); } }
///<summary>Updates one PayPeriod in the database. Uses an old object to compare to, and only alters changed fields. This prevents collisions and concurrency problems in heavily used tables.</summary> internal static void Update(PayPeriod payPeriod,PayPeriod oldPayPeriod) { string command=""; if(payPeriod.DateStart != oldPayPeriod.DateStart) { if(command!=""){ command+=",";} command+="DateStart = "+POut.Date(payPeriod.DateStart)+""; } if(payPeriod.DateStop != oldPayPeriod.DateStop) { if(command!=""){ command+=",";} command+="DateStop = "+POut.Date(payPeriod.DateStop)+""; } if(payPeriod.DatePaycheck != oldPayPeriod.DatePaycheck) { if(command!=""){ command+=",";} command+="DatePaycheck = "+POut.Date(payPeriod.DatePaycheck)+""; } if(command==""){ return; } command="UPDATE payperiod SET "+command +" WHERE PayPeriodNum = "+POut.Long(payPeriod.PayPeriodNum); Db.NonQ(command); }
///<summary>Updates one PayPeriod in the database.</summary> internal static void Update(PayPeriod payPeriod) { string command="UPDATE payperiod SET " +"DateStart = "+POut.Date (payPeriod.DateStart)+", " +"DateStop = "+POut.Date (payPeriod.DateStop)+", " +"DatePaycheck= "+POut.Date (payPeriod.DatePaycheck)+" " +"WHERE PayPeriodNum = "+POut.Long(payPeriod.PayPeriodNum); Db.NonQ(command); }
public static void ReCalculatePeriod() { using (var db = new RentBikeEntities()) { var contracts = db.Contracts.Where(c => c.CONTRACT_STATUS == true).ToList(); foreach (var contract in contracts) { List<PayPeriod> lstPay = db.PayPeriods.Where(c => c.CONTRACT_ID == contract.ID).ToList(); int div = lstPay.Count % 3; if (div > 0) { div = 3 - div; PayPeriod lastPay = lstPay.LastOrDefault(); for (int i = 1; i <= div; i++) { PayPeriod pp = new PayPeriod(); pp.CONTRACT_ID = contract.ID; pp.PAY_DATE = lastPay.PAY_DATE.AddDays(i * 10); pp.AMOUNT_PER_PERIOD = lastPay.AMOUNT_PER_PERIOD; pp.STATUS = true; pp.ACTUAL_PAY = 0; db.PayPeriods.Add(pp); } } } db.SaveChanges(); } }
private static PayPeriod CreateOneMorePayPeriod(RentBikeEntities db, Contract contract, PayPeriod lastPeriod, decimal multipleFee, decimal increateFeeCar, decimal increateFeeEquip, decimal increateFeeOther, bool bFirstCreated) { PayPeriod pp1 = new PayPeriod(); pp1.CONTRACT_ID = contract.ID; if (bFirstCreated) { pp1.PAY_DATE = lastPeriod.PAY_DATE; pp1.AMOUNT_PER_PERIOD = increateFeeCar; } else { pp1.PAY_DATE = lastPeriod.PAY_DATE.AddDays(10); if (contract.FEE_PER_DAY > 0) { switch (contract.RENT_TYPE_ID) { case 1: if (((contract.FEE_PER_DAY / multipleFee)) < RentCarFeePerDay) { var countPeriod = db.PayPeriods.Where(c => c.CONTRACT_ID == contract.ID).Count(); if (countPeriod <= 3) increateFeeCar = (contract.FEE_PER_DAY * 10) + (multipleFee * 50 * 10); else if (countPeriod > 3) increateFeeCar = (contract.FEE_PER_DAY * 10) + (multipleFee * 100 * 10); pp1.AMOUNT_PER_PERIOD = increateFeeCar; } else { if (contract.FEE_PER_DAY < (lastPeriod.AMOUNT_PER_PERIOD / 10)) pp1.AMOUNT_PER_PERIOD = lastPeriod.AMOUNT_PER_PERIOD; else { if (((contract.FEE_PER_DAY / multipleFee) * 10) < 4000) pp1.AMOUNT_PER_PERIOD = increateFeeCar; else pp1.AMOUNT_PER_PERIOD = increateFeeOther; } } break; case 2: if (contract.FEE_PER_DAY < (lastPeriod.AMOUNT_PER_PERIOD / 10)) pp1.AMOUNT_PER_PERIOD = lastPeriod.AMOUNT_PER_PERIOD; else { if (((contract.FEE_PER_DAY / multipleFee) * 10) < 4000) pp1.AMOUNT_PER_PERIOD = increateFeeCar; else pp1.AMOUNT_PER_PERIOD = increateFeeOther; } break; //case 2: // if (((contract.FEE_PER_DAY / multipleFee) * 10) < 6000) // pp1.AMOUNT_PER_PERIOD = increateFeeEquip; // else // pp1.AMOUNT_PER_PERIOD = increateFeeOther; // break; default: pp1.AMOUNT_PER_PERIOD = increateFeeOther; break; } } else pp1.AMOUNT_PER_PERIOD = increateFeeCar; } pp1.STATUS = true; pp1.ACTUAL_PAY = 0; PayPeriod pp2 = new PayPeriod(); pp2.CONTRACT_ID = contract.ID; if (bFirstCreated) pp2.PAY_DATE = pp1.PAY_DATE.AddDays(9); else pp2.PAY_DATE = pp1.PAY_DATE.AddDays(10); pp2.AMOUNT_PER_PERIOD = pp1.AMOUNT_PER_PERIOD; pp2.STATUS = true; pp2.ACTUAL_PAY = 0; PayPeriod pp3 = new PayPeriod(); pp3.CONTRACT_ID = contract.ID; pp3.PAY_DATE = pp2.PAY_DATE.AddDays(10); pp3.AMOUNT_PER_PERIOD = pp1.AMOUNT_PER_PERIOD; pp3.STATUS = true; pp3.ACTUAL_PAY = 0; db.PayPeriods.Add(pp1); db.PayPeriods.Add(pp2); db.PayPeriods.Add(pp3); db.SaveChanges(); return pp3; }