public List <SavingInterestsPostingEvent> PostingInterests(DateTime postingDate) { List <SavingInterestsPostingEvent> list = new List <SavingInterestsPostingEvent>(); DateTime lastPostingDate = _saving.GetLastPostingDate(); DateTime currentPostingDate; while (DateCalculationStrategy.DateCalculationWeekly(lastPostingDate, postingDate, _weekEndDay2)) { currentPostingDate = DateCalculationStrategy.GetNextWeekly(lastPostingDate, _weekEndDay2); currentPostingDate = new DateTime(currentPostingDate.Year, currentPostingDate.Month, currentPostingDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); OCurrency interestsToPost = 0; foreach (SavingEvent savEvent in _saving.Events) { if (savEvent is SavingInterestsAccrualEvent && savEvent.Date <= currentPostingDate && savEvent.Date > lastPostingDate) { interestsToPost += savEvent.Amount.Value; } } list.Add(new SavingInterestsPostingEvent { Date = currentPostingDate, Amount = interestsToPost, Description = string.Format("Posting interests for period : {0:d} to {1:d} : {2}", lastPostingDate, currentPostingDate, _saving.Code), User = _user, Cancelable = true, ProductType = _saving.Product.GetType(), Branch = _saving.Branch, Currency = _saving.Product.Currency, ContracId = _saving.Id }); lastPostingDate = currentPostingDate; } return(list); }
public List <SavingInterestsPostingEvent> PostingInterests(DateTime postingDate) { List <SavingInterestsPostingEvent> list = new List <SavingInterestsPostingEvent>(); DateTime lastPostingDate = _saving.GetLastPostingDate(); DateTime currentPostingDate; while (DateCalculationStrategy.DateCalculationMonthly(lastPostingDate, postingDate)) { currentPostingDate = new DateTime(lastPostingDate.AddMonths(1).Year, lastPostingDate.AddMonths(1).Month, 01, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); OCurrency interestsToPost = _saving.Events.Where( savEvent => savEvent is SavingInterestsAccrualEvent && savEvent.Date <= currentPostingDate && savEvent.Date >= lastPostingDate).Aggregate <SavingEvent, OCurrency>(0, (current, savEvent) => current + savEvent.Amount.Value); list.Add(new SavingInterestsPostingEvent { Date = currentPostingDate, Amount = interestsToPost, Description = string.Format("Posting interests for period : {0:d} to {1:d} : {2}", lastPostingDate, currentPostingDate, _saving.Code), User = _user, Cancelable = true, ProductType = _saving.Product.GetType(), Branch = _saving.Branch, Currency = _saving.Product.Currency, ContracId = _saving.Id }); lastPostingDate = lastPostingDate.AddMonths(1); } return(list); }
public List <SavingInterestsPostingEvent> PostingInterests(DateTime postingDate) { List <SavingInterestsPostingEvent> list = new List <SavingInterestsPostingEvent>(); if (_saving.UseTermDeposit) { DateTime lastPostingDate = _saving.GetLastPostingDate(); OCurrency interestsToPost; interestsToPost = _saving.Events.Where(item => item is SavingInterestsAccrualEvent && item.Date.Date > lastPostingDate && item.Date.Date <= postingDate && item.Deleted == false).Sum(item => item.Amount.Value); if (postingDate.Date == _saving.NextMaturity.Value.Date) { list.Add(new SavingInterestsPostingEvent { Date = new DateTime(postingDate.Year, postingDate.Month, postingDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), Description = string.Format("Posting interests for period : {0:d} to {1:d} : {2}", lastPostingDate, postingDate, _saving.Code ), Amount = interestsToPost, User = _user, Cancelable = true, ProductType = _saving.Product.GetType() }); } } else { DateTime lastPostingDate = _saving.GetLastPostingDate(); DateTime currentPostingDate; while (DateCalculationStrategy.DateCalculationDiary(lastPostingDate, postingDate)) { currentPostingDate = lastPostingDate.AddDays(1); OCurrency interestsToPost = 0; foreach (SavingEvent savEvent in _saving.Events) { if (savEvent is SavingInterestsAccrualEvent && savEvent.Date.Date <= currentPostingDate.Date && savEvent.Date.Date > lastPostingDate.Date) { interestsToPost += savEvent.Amount.Value; } } list.Add(new SavingInterestsPostingEvent { Date = new DateTime(currentPostingDate.Year, currentPostingDate.Month, currentPostingDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), Description = string.Format("Posting interests for period : {0:d} to {1:d} : {2}", lastPostingDate, currentPostingDate, _saving.Code), Amount = interestsToPost, User = _user, Cancelable = true, ProductType = _saving.Product.GetType(), Branch = _saving.Branch, Currency = _saving.Product.Currency, ContracId = _saving.Id }); lastPostingDate = lastPostingDate.AddDays(1); } } return(list); }