private void SetLastRemainderDateOf(BudgetWeek week)
        {
            var lastRemainder = Remainders[week].LastOrDefault();

            if (lastRemainder != null)
            {
                lastRemainderDate[week] = lastRemainder.Date;
            }
            else
            {
                lastRemainderDate[week] = week.FirstDay.AddDays(-1);
            }
        }
        private void CalculateRemaindersForDates(BudgetWeek week, IEnumerable <DateTime> dates)
        {
            foreach (var date in dates)
            {
                var calculatedRemainder =
                    PriorWeekRemainder(week) -
                    DayEnvelopeSize * ((date - week.FirstDay).Days + 1);

                var period = new Period(week.FirstDay, date.AddDays(1));

                var remainder = calculatedRemainder +
                                CashMovements[period].Sum(_ => _.Amount) +
                                MonthlyCashMovements[period].Sum(_ => _.Amount);

                budget.SetRemainder(date, remainder);
            }
        }
        private void CalculateTotalRemainders()
        {
            for (var week = new BudgetWeek(Period.From); week.From < Period.To; week = new BudgetWeek(week.To))
            {
                budget.AddWeek(week);

                SetLastRemainderDateOf(week);

                var daysToCalculate = new Set <DateTime> {
                    week.FirstDay, week.LastDay
                };
                daysToCalculate.AddRange(CashInvestmentDates(week));
                daysToCalculate.AddRange(MonthlyExpensesDates(week));
                CalculateRemaindersForDates(week, daysToCalculate);
            }

            budgetWeeks = new DatedSet <BudgetWeek>(budget.Weeks);
        }
Example #4
0
 internal void AddWeek(BudgetWeek week)
 {
     weeks.Add(week);
 }
 private static IEnumerable <DateTime> DatesWithin <T>(BudgetWeek week, DatedSet <T> transfers) where T : IDated
 {
     return(transfers[week].Convert(i => i.Date).Distinct());
 }
 private IEnumerable <DateTime> MonthlyExpensesDates(BudgetWeek week)
 {
     return(DatesWithin(week, MonthlyCashMovements));
 }
 private IEnumerable <DateTime> CashInvestmentDates(BudgetWeek week)
 {
     return(DatesWithin(week, CashMovements));
 }
 private int PriorWeekRemainder(BudgetWeek week)
 {
     return(budget.GetRemainder(week.FirstDay.AddDays(-1)));
 }