public static Results Analyse(TermsEntity termsEntity) { var currentDate = termsEntity.Start; var daysWorkedThisWeek = 0; var contractAnalysesResults = new Results(termsEntity); var weekIndex = 0; for (var day = 0; day < 7 * (termsEntity.DurationWeeks + termsEntity.LieuPaymentWeeks); day++) { if (!DateInterogater.IsWeekend(currentDate) && day < 7 * termsEntity.DurationWeeks) { daysWorkedThisWeek += 1; } else if (daysWorkedThisWeek > 0) { var weeklyAnalyses = new WeeklyAnalyses(weekIndex, daysWorkedThisWeek, termsEntity); contractAnalysesResults.WeeklyAnalyseses.Add(weeklyAnalyses); daysWorkedThisWeek = 0; weekIndex++; } currentDate = currentDate.AddDays(1); } return contractAnalysesResults; }
public WeeklyAnalyses(int weekIndex, int daysWorked, TermsEntity termsEntity) { WeekIndex = weekIndex; DaysWorked = daysWorked; _termsEntity = termsEntity; BusinessWeekStart = _termsEntity.Start.AddDays(7 * weekIndex).ToStartOfBusinessWeek(); BusinessWeekEnd = _termsEntity.Start.AddDays(7 * weekIndex).ToEndOfBusinessWeek(); }
public void FourWeekBasic_Future() { var start = new DateTime(2013, 01, 01); var now = new DateTime(2010, 01, 01); const int durationWeeks = 12; var terms = new TermsEntity(start, durationWeeks, 330, 1, 0.04, 0.16, 0, now); var car = new Results(terms) { Now = now }; for (var i = 0; i < durationWeeks; i++) { car.WeeklyAnalyseses.Add(new WeeklyAnalyses(i, i == 0 ? 1 : 5, terms)); } Assert.IsNull(car.CurrentWeekIndexZeroBased); Assert.AreEqual(0, car.WorkDaysPaid); }
public void FourWeekBasic_FithFridayOfSecondContract() { var start = new DateTime(2013, 01, 25); var now = new DateTime(2013, 02, 22); const int durationWeeks = 12; var terms = new TermsEntity(start, durationWeeks, 330, 1, 0.04, 0.16, 0, now); var car = new Results(terms) { Now = now }; for (var i = 0; i < durationWeeks; i++) { car.WeeklyAnalyseses.Add(new WeeklyAnalyses(i, i == 0 ? 1 : 5, terms)); } Assert.AreEqual(4, car.CurrentWeekIndexZeroBased); Assert.AreEqual(16, car.WorkDaysPaid); Assert.AreEqual(845, Math.Round(car.VatDueToDate)); }
private static Results SetupBasic(DateTime start, DateTime now, int durationWeeks) { if (start.DayOfWeek != DayOfWeek.Monday) { throw new NotSupportedException("Assumption is 5 days per week are worked"); } var terms = new TermsEntity(start, durationWeeks, 100, 1, 0.04, 0.16, 0, now); var car = new Results(terms) { Now = now }; for (var i = 0; i < durationWeeks; i++) { car.WeeklyAnalyseses.Add(new WeeklyAnalyses(i, 5, terms)); } return car; }
public void FourWeekBasic_StartingOnFriday() { var start = Start.AddDays(5); var now = Start.AddDays(5); const int durationWeeks = 12; var terms = new TermsEntity(start, durationWeeks, 100, 1, 0.04, 0.16, 0, now); var car = new Results(terms) { Now = now }; for (var i = 0; i < durationWeeks; i++) { car.WeeklyAnalyseses.Add(new WeeklyAnalyses(i, i == 0 ? 1 : 5, terms)); } Assert.AreEqual(0, car.CurrentWeekIndexZeroBased); Assert.AreEqual(new DateTime(2010, 02, 05), car.WeeklyAnalyseses[0].BusinessWeekEnd); Assert.AreEqual(new DateTime(2010, 02, 01), car.WeeklyAnalyseses[0].BusinessWeekStart); Assert.AreEqual(0, car.VatDueToDate); }
public Results(TermsEntity terms) { Terms = terms; WeeklyAnalyseses = new List<WeeklyAnalyses>(); Now = DateTime.Now; }
public static void Visualise(TermsEntity terms) { var results = Analyser.Analyse(terms); Printer.Print(results); }