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);
        }
Beispiel #2
0
        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))
            {
                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);
        }