public void SavingServicesAccountAtMaturity(ISavingsContract savingContract, DateTime date, User user) { if (savingContract.Rollover == OSavingsRollover.None) { CloseAndTransfer(savingContract, savingContract.TransferAccount, date, user, savingContract.GetBalance(date), true, Teller.CurrentTeller); } if (savingContract.Rollover == OSavingsRollover.Principal) { DateTime lastMaturity = DateCalculationStrategy.GetLastMaturity(date, savingContract.Product.Periodicity, savingContract.NumberOfPeriods); OCurrency interests = savingContract.Events.Where( item => item is SavingInterestsPostingEvent && item.Date.Date > lastMaturity && item.Date.Date <= date ). Sum(item => item.Amount.Value); // TODO: replace the fee of zero with a meaningful value Transfer(TransferAccount, interests, 0, date, "Transfer interests"); } }
public void PostingInterests_TenPosting() { // Assert.Ignore(); SavingsBookProduct product = new SavingsBookProduct { Id = 1, InterestBase = OSavingInterestBase.Daily, InterestFrequency = OSavingInterestFrequency.EndOfDay, Periodicity = new InstallmentType("Daily", 1, 0) }; DateTime postingDate = new DateTime(2009, 01, 10); SavingBookContract saving = new SavingBookContract( ApplicationSettings.GetInstance(""), new User(), new DateTime(2009, 01, 01), null) { Product = product, InterestRate = 0.1, NextMaturity = new DateTime(2009, 01, 01) }; List <SavingInterestsPostingEvent> list = new List <SavingInterestsPostingEvent>(); List <SavingInterestsAccrualEvent> savingInterestsAccrualEvents = saving.CalculateInterest( new DateTime(2009, 01, 10), new User { Id = 1 }); foreach (SavingInterestsAccrualEvent accrualEvent in savingInterestsAccrualEvents) { saving.Events.Add(accrualEvent); } saving.NextMaturity = saving.CreationDate.AddDays(-1); while ( DateCalculationStrategy.GetNextMaturity(saving.NextMaturity.Value, saving.Product.Periodicity, 1) <= postingDate) { saving.NextMaturity = DateCalculationStrategy.GetNextMaturity(saving.NextMaturity.Value, saving.Product.Periodicity, 1); list.AddRange(saving.PostingInterests(saving.NextMaturity.Value, new User { Id = 1 })); foreach (var postingEvent in list) { saving.Events.Add(postingEvent); } list.Clear(); } Assert.AreEqual(10, saving.Events.FindAll(item => item is SavingInterestsPostingEvent).Count); }
public List <SavingInterestsAccrualEvent> CalculateInterest(DateTime pClosureDate) { List <SavingInterestsAccrualEvent> listInterestsAccrualEvent = new List <SavingInterestsAccrualEvent>(); DateTime lastClosureDate = _saving.GetLastAccrualDate(); while (DateCalculationStrategy.DateCalculationMonthly(lastClosureDate, pClosureDate)) { DateTime accrualDate = new DateTime(lastClosureDate.AddMonths(1).Year, lastClosureDate.AddMonths(1).Month, 01, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); int count = _saving.Events.FindAll(se => (se.Code == OSavingEvents.Withdraw || se.Code == OSavingEvents.DebitTransfer /* || * se.Code == OSavingEvents.SpecialOperationDebit*/) && (se.Date > lastClosureDate && se.Date < accrualDate)).Count; if (count < 3) { if (!_checkUsage) { listInterestsAccrualEvent.Add(GetInterests(lastClosureDate, accrualDate)); } else { //slycode SavingInitialDepositEvent firstDeposit = null; foreach (var evnt in _saving.Events) { if (evnt is SavingInitialDepositEvent) { firstDeposit = (SavingInitialDepositEvent)evnt; if (DateCalculationStrategy.DateCalculationMonthly(firstDeposit.Date, DateTime.Now, -3)) { listInterestsAccrualEvent.Add(GetInterests(lastClosureDate, accrualDate)); } break; } } } } lastClosureDate = lastClosureDate.AddMonths(1); } return(listInterestsAccrualEvent); }
public List <SavingInterestsAccrualEvent> CalculateInterest(DateTime pClosureDate) { List <SavingInterestsAccrualEvent> listInterestsAccrualEvent = new List <SavingInterestsAccrualEvent>(); DateTime lastClosureDate = _saving.GetLastAccrualDate(); while (DateCalculationStrategy.DateCalculationMonthly(lastClosureDate, pClosureDate)) { DateTime accrualDate = new DateTime(lastClosureDate.AddMonths(1).Year, lastClosureDate.AddMonths(1).Month, 01, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); listInterestsAccrualEvent.Add(GetInterests(lastClosureDate, accrualDate)); lastClosureDate = lastClosureDate.AddMonths(1); } return(listInterestsAccrualEvent); }
private List <SavingEvent> PostingEndOfDay(DateTime pDate, User pUser) { DateTime lastPostingDate = GetLastPostingDate(); List <SavingEvent> events = new List <SavingEvent>(); while (DateCalculationStrategy.DateCalculationDiary(lastPostingDate, pDate)) { lastPostingDate = lastPostingDate.AddDays(1); events.AddRange(AddSavingEvent(CalculateInterest(new DateTime(lastPostingDate.Year, lastPostingDate.Month, lastPostingDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), pUser))); events.AddRange(AddSavingEvent(PostingInterests(new DateTime(lastPostingDate.Year, lastPostingDate.Month, lastPostingDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), pUser))); } return(events); }
public List <SavingInterestsAccrualEvent> CalculateInterest(DateTime pClosureDate) { List <SavingInterestsAccrualEvent> listInterestsAccrualEvent = new List <SavingInterestsAccrualEvent>(); DateTime lastClosureDate = _saving.GetLastAccrualDate(); while (DateCalculationStrategy.DateCalculationWeekly(lastClosureDate, pClosureDate, _weekEndDay2)) { DateTime cDate = new DateTime(lastClosureDate.Year, lastClosureDate.Month, lastClosureDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); DateTime accrualDate = DateCalculationStrategy.GetNextWeekly(cDate, _weekEndDay2); listInterestsAccrualEvent.Add(GetInterests(lastClosureDate, accrualDate)); lastClosureDate = accrualDate; } return(listInterestsAccrualEvent); }
private List <SavingEvent> DoClosureWithTermDeposit(DateTime date, User user) { List <SavingEvent> savingEvents = DoClosureWithoutTermDeposit(date, user); List <SavingEvent> events = new List <SavingEvent>(); while (NextMaturity <= date) { if (Rollover == OSavingsRollover.Principal) { DateTime transferDate = NextMaturity.GetValueOrDefault(); if (NextMaturity.Value.Date == CreationDate.Date) { NextMaturity = NextMaturity.Value.AddDays(-1); } NextMaturity = DateCalculationStrategy.GetNextMaturity(NextMaturity.Value, Product.Periodicity, NumberOfPeriods); int previousPeriodCount = this.Events.FindAll(item => item is SavingInterestsPostingEvent && item.Deleted == false).Count; if (AccountAtMaturityEvent != null && previousPeriodCount % NumberOfPeriods == 0) { AccountAtMaturityEvent(this, transferDate, user); } } else if (Rollover == OSavingsRollover.PrincipalAndInterests) { if (NextMaturity.Value.Date == CreationDate.Date) { NextMaturity = NextMaturity.Value.AddDays(-1); } NextMaturity = DateCalculationStrategy.GetNextMaturity(NextMaturity.Value, Product.Periodicity, NumberOfPeriods); } } events.AddRange(AddSavingEvent(CalculateInterest(date, user))); savingEvents.AddRange(events); return(savingEvents); }
private List <SavingEvent> PostingEndOfWeek(DateTime pDate, User pUser) { DateTime lastPostingDate = GetLastPostingDate(); List <SavingEvent> events = new List <SavingEvent>(); while (DateCalculationStrategy.DateCalculationWeekly(lastPostingDate, pDate, ApplicationSettings.WeekEndDay2)) { lastPostingDate = DateCalculationStrategy.GetNextWeekly(lastPostingDate, ApplicationSettings.WeekEndDay2); events.AddRange(AddSavingEvent(CalculateInterest(new DateTime(lastPostingDate.Year, lastPostingDate.Month, lastPostingDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), pUser))); events.AddRange(AddSavingEvent(PostingInterests(new DateTime(lastPostingDate.Year, lastPostingDate.Month, lastPostingDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), pUser))); } events.AddRange(AddSavingEvent(CalculateInterest(pDate, pUser))); return(events); }
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 void PostingInterests_OnePosting() { SavingsBookProduct product = new SavingsBookProduct { Id = 1, InterestBase = OSavingInterestBase.Daily, InterestFrequency = OSavingInterestFrequency.EndOfMonth, Periodicity = new InstallmentType("Monthly", 0, 1) }; User user = new User() { Id = 1 }; DateTime closureDate = new DateTime(2009, 02, 01); SavingBookContract saving = new SavingBookContract( ApplicationSettings.GetInstance(""), user, new DateTime(2009, 01, 01), null ) { Product = product, InterestRate = 0.1 }; saving.NextMaturity = DateCalculationStrategy.GetNextMaturity(saving.CreationDate.Date, saving.Periodicity, 1); List <SavingInterestsAccrualEvent> savingInterestsAccrualEvents = saving.CalculateInterest(closureDate, user); foreach (var accrualEvent in savingInterestsAccrualEvents) { saving.Events.Add(accrualEvent); } List <SavingInterestsPostingEvent> list = new List <SavingInterestsPostingEvent>(); list = saving.PostingInterests(closureDate, user); Assert.AreEqual(1, list.Count); }
private List <SavingEvent> PostingEndOfMonth(DateTime pDate, User pUser) { DateTime lastPostingDate = GetLastPostingDate(); List <SavingEvent> events = new List <SavingEvent>(); while (DateCalculationStrategy.DateCalculationMonthly(lastPostingDate, pDate)) { lastPostingDate = lastPostingDate.AddMonths(1); events.AddRange(AddSavingEvent(CalculateInterest(new DateTime(lastPostingDate.Year, lastPostingDate.Month, 01, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), pUser))); events.AddRange(AddSavingEvent(PostingInterests(new DateTime(lastPostingDate.Year, lastPostingDate.Month, 01, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), pUser))); } if ((Product).InterestBase != OSavingInterestBase.Monthly) { events.AddRange(AddSavingEvent(CalculateInterest(pDate, pUser))); } return(events); }
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 <SavingInterestsAccrualEvent> CalculateInterest(DateTime pClosureDate) { List <SavingInterestsAccrualEvent> listInterestsAccrualEvent = new List <SavingInterestsAccrualEvent>(); DateTime lastClosureDate = new DateTime(_saving.GetLastAccrualDate().Year, _saving.GetLastAccrualDate().Month, _saving.GetLastAccrualDate().Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); while (DateCalculationStrategy.DateCalculationDiary(lastClosureDate, pClosureDate)) { if (lastClosureDate.Date == _saving.CreationDate.Date && listInterestsAccrualEvent.Count == 0) { lastClosureDate = lastClosureDate.AddDays(-1); } lastClosureDate = lastClosureDate.AddDays(1); listInterestsAccrualEvent.Add(GetInterests(lastClosureDate)); } return(listInterestsAccrualEvent); }
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); }
public void PostingInterests_12Posting() { // Assert.Ignore(); SavingsBookProduct product = new SavingsBookProduct { Id = 1, InterestBase = OSavingInterestBase.Daily, InterestFrequency = OSavingInterestFrequency.EndOfMonth, Periodicity = new InstallmentType("Monthly", 0, 1) }; User user = new User() { Id = 1 }; DateTime creationDate = new DateTime(2009, 01, 01); SavingBookContract saving = new SavingBookContract( ApplicationSettings.GetInstance(""), user, creationDate, null ) { Product = product, InterestRate = 0.1 }; DateTime closureDate = new DateTime(2010, 01, 01); saving.NextMaturity = saving.CreationDate.Date; saving.NumberOfPeriods = 1; saving.FirstDeposit(1000, creationDate, 0, user, new Teller()); saving.NextMaturity = DateCalculationStrategy.GetNextMaturity( saving.CreationDate.Date, saving.Product.Periodicity, saving.NumberOfPeriods); List <SavingInterestsAccrualEvent> interestsAccrualEvents = saving.CalculateInterest(closureDate, new User { Id = 1 }); foreach (var accrualEvent in interestsAccrualEvents) { saving.Events.Add(accrualEvent); } List <SavingInterestsPostingEvent> list = new List <SavingInterestsPostingEvent>(); List <SavingInterestsPostingEvent> postingEvents = new List <SavingInterestsPostingEvent>(); while (saving.NextMaturity.Value <= closureDate) { list = saving.PostingInterests(saving.NextMaturity.Value, new User() { Id = 1 }); postingEvents.AddRange(list); foreach (var postingEvent in list) { saving.Events.Add(postingEvent); } saving.NextMaturity = DateCalculationStrategy.GetNextMaturity(saving.NextMaturity.Value, saving.Periodicity, 1); } list = saving.PostingInterests(new DateTime(2010, 01, 01), new User { Id = 1 }); Assert.AreEqual(12, postingEvents.Count); }
public DateTime GetNextMaturity(DateTime currentMaturityDate, InstallmentType periodicity) { return(DateCalculationStrategy.GetNextMaturity(currentMaturityDate, periodicity, 1)); }