Esempio n. 1
0
        public PlanOfPaymentModel GetPaymentSchedule(int creditId)
        {
            var credit = Context.Credits.FirstOrDefault(e => e.Id == creditId);

            PlanOfPaymentModel result = new PlanOfPaymentModel();

            result.CreditId        = credit.Id;
            result.CurrentDay      = SystemInformationService.CurrentBankDay;
            result.PaymentSchedule = new Dictionary <DateTime, double>();

            int    countMonthes    = credit.PlanOfCredit.MonthPeriod;
            double percentPerMonth = credit.PlanOfCredit.Percent / SystemInformationService.CountMonthesInYear;

            if (credit.PlanOfCredit.Anuity)
            {
                double anuityCoefficient =
                    (percentPerMonth * Math.Pow(1 + percentPerMonth, countMonthes)) /
                    (Math.Pow(1 + percentPerMonth, countMonthes) - 1);

                double paymentPerMonth = anuityCoefficient * (double)credit.Amount;

                DateTime paymentDate = credit.StartDate.AddMonths(1);
                for (int i = 0; i < countMonthes; i++)
                {
                    result.PaymentSchedule.Add(paymentDate, paymentPerMonth);

                    paymentDate = paymentDate.AddMonths(1);
                }
            }
            else
            {
                double creditRest = (double)credit.Amount;
                double monthlyReturningCreditBodyPart = (double)credit.Amount / countMonthes;

                DateTime paymentDate = credit.StartDate.AddMonths(1);
                for (int i = 0; i < countMonthes; i++)
                {
                    double thisMonthPayment = monthlyReturningCreditBodyPart + creditRest * percentPerMonth;
                    result.PaymentSchedule.Add(paymentDate, thisMonthPayment);

                    creditRest -= monthlyReturningCreditBodyPart;
                    paymentDate = paymentDate.AddMonths(1);
                }
            }

            return(result);
        }
Esempio n. 2
0
        public PlanOfPaymentModel GetPaymentSchedule(int creditId)
        {
            var credit = Context.Credits.FirstOrDefault(e => e.Id == creditId);
            PlanOfPaymentModel result = new PlanOfPaymentModel();

            result.CreditId   = credit.Id;
            result.CurrentDay = CommonService.StartDate +
                                new TimeSpan(CommonService.CurrentBankDay, 0, 0, 0);

            decimal allAmount = credit.Amount +
                                credit.Amount * (credit.EndDate - credit.StartDate) *
                                (decimal)credit.PlanOfCredit.Percent / 100 / CommonService.YearLength;
            decimal montlyAmount = credit.PlanOfCredit.Anuity
                ? allAmount / (credit.EndDate - credit.StartDate) * CommonService.MonthLength
                : credit.Amount * CommonService.MonthLength *
                                   (decimal)credit.PlanOfCredit.Percent / 100 / CommonService.YearLength;

            result.PaymentSchedule = new Dictionary <DateTime, decimal>();
            decimal tempAmount = 0;

            for (int i = credit.StartDate + CommonService.MonthLength;
                 i <= credit.EndDate;
                 i += CommonService.MonthLength)
            {
                tempAmount += montlyAmount;
                result.PaymentSchedule.Add(CommonService.StartDate + new TimeSpan(i, 0, 0, 0), montlyAmount);
            }
            DateTime endDate = CommonService.StartDate + new TimeSpan(credit.EndDate, 0, 0, 0);

            if (result.PaymentSchedule.Keys.Contains(endDate))
            {
                result.PaymentSchedule[endDate] += allAmount - tempAmount;
            }
            else
            {
                result.PaymentSchedule.Add(endDate, allAmount - tempAmount);
            }
            return(result);
        }