public AmortizationReport GenerateReport(LoanEntity loan,
                                                 Dictionary <DateTime, double> paymentChangesByDate)
        {
            int       loanLength   = LoanTermCalculator.GetMonthsUntilPaid(loan).getMonthsUntilPaidOff();
            ArrayList paymentDates = DateUtil.GetListOfDatesMonthApart(DateUtil.GetNow(), loanLength);

            AmortizationReport report  = new AmortizationReport(loan);
            double             balance = loan.GetCurrentBalance();

            foreach (DateTime date in paymentDates)
            {
                DateTime balanceEffectiveDate = DateUtil.FindDateBeforeFromList(date, new List <DateTime>(paymentChangesByDate.Keys));

                double paymentForDate = date == balanceEffectiveDate?loan.GetMinimumMonthlyPayment() : paymentChangesByDate[balanceEffectiveDate];

                AmortizationRow row = new AmortizationRowGenerator()
                                      .GenerateRow(report.GetReportRows().Count + 1,
                                                   balance,
                                                   loan.GetMonthlyInterestRate(),
                                                   paymentForDate,
                                                   date);
                report.AddRow(row);
                balance = row.GetBalance();
                if (balance < 0)
                {
                    break;
                }
            }
            return(report);
        }
        public List <AmortizationReport> GenerateReport(List <LoanEntity> loans)
        {
            List <AmortizationReport> reports = new List <AmortizationReport>();

            List <LoanEntity> sortedLoans = loans.OrderBy(x => x.GetCurrentBalance()).ToList();

            double   accumulatedAdditionalPayment = 0;
            DateTime previousLoanPayoffDate       = DateTime.MinValue;

            foreach (LoanEntity loan in sortedLoans)
            {
                Dictionary <DateTime, double> paymentChanges = new Dictionary <DateTime, double>();

                if (previousLoanPayoffDate != DateTime.MinValue)
                {
                    paymentChanges.Add(previousLoanPayoffDate.AddMonths(1), loan.GetMinimumMonthlyPayment() + accumulatedAdditionalPayment);
                }

                AmortizationReport report = AmortizationReportGenerator.GenerateReport(loan, paymentChanges);

                reports.Add(report);
                previousLoanPayoffDate        = AmortizationReportEvaluator.GetLoanPaidOffDateFromReport(report);
                accumulatedAdditionalPayment += loan.GetMinimumMonthlyPayment();
            }

            return(reports);
        }
Example #3
0
        static void Main(string[] args)
        {
            LoanEntity loan = LoanEntity.NewBuilder()
                              .SetLoanName("Test Loan")
                              .SetPrinciple(20000)
                              .SetCurrentBalance(20000)
                              .SetApr(.006155 * 12)
                              .SetMinuminMonthlyPayment(415.76)
                              .Build();
            LoanEntity secondLoan = LoanEntity.NewBuilder()
                                    .SetLoanName("Test Loan")
                                    .SetPrinciple(5000)
                                    .SetCurrentBalance(5000)
                                    .SetApr(.006155 * 12)
                                    .SetMinuminMonthlyPayment(200)
                                    .Build();

            Console.WriteLine("Expected length of loan paying minimum : " + new LoanTermCalculator()
                              .GetMonthsUntilPaid(loan)
                              .getMonthsUntilPaidOff());

            Dictionary <DateTime, double> payementChanges = new Dictionary <DateTime, double>
            {
                //{ DateTime.Now.AddMonths(5), 550.0 }
            };

            AmortizationReportGenerator amortizationReportGenerator = new AmortizationReportGenerator(new LoanTermCalculator(),
                                                                                                      new DateUtil());

            AmortizationReport report = amortizationReportGenerator.GenerateReport(loan,
                                                                                   payementChanges);

            AmortizationReport secondReport = amortizationReportGenerator.GenerateReport(secondLoan,
                                                                                         payementChanges);
            AmortizationReportConsolePrinter printer = new AmortizationReportConsolePrinter();

            printer.PrintReport(report);
            printer.PrintReport(secondReport);

            SnowBallReportGenerator snowBallReportGenerator = new SnowBallReportGenerator(amortizationReportGenerator,
                                                                                          new AmortizationReportEvaluator());
            List <LoanEntity> loans = new List <LoanEntity> {
                loan, secondLoan
            };
            List <AmortizationReport> snowBallReports = snowBallReportGenerator.GenerateReport(loans);

            foreach (AmortizationReport snowReport in snowBallReports)
            {
                printer.PrintReport(snowReport);
            }
        }
        public void PrintReport(AmortizationReport report)
        {
            LoanEntity loan = report.GetLoan();

            Console.WriteLine("LOAN AT TIME OF REPORT");
            Console.WriteLine("".PadRight(20) +
                              "PAYMENT AMOUNT".PadRight(20) +
                              "INTEREST".PadRight(20) +
                              "PRINCIPAL".PadRight(20) +
                              "BALANCE".PadRight(20));

            Console.WriteLine("Initial".PadRight(20) + "".PadRight(20) + "".PadRight(20) + "".PadRight(20) + loan.GetCurrentBalance().ToString().PadRight(20));

            foreach (AmortizationRow row in report.GetReportRows())
            {
                Console.WriteLine(row.GetPaymentNumber().ToString().PadRight(20) +
                                  row.GetPaymentAmount().ToString().PadRight(20) +
                                  row.GetInterest().ToString().PadRight(20) +
                                  row.GetPrincipal().ToString().PadRight(20) +
                                  row.GetBalance().ToString().PadRight(20));
            }
        }
        public DateTime GetLoanPaidOffDateFromReport(AmortizationReport report)
        {
            List <AmortizationRow> rows = report.GetReportRows();

            return(rows[rows.Count - 1].GetPaymentDate());
        }
        public double GetAmountBeingPaidAtEndOfLoan(AmortizationReport report)
        {
            List <AmortizationRow> rows = report.GetReportRows();

            return(rows[rows.Count - 1].GetPaymentAmount());
        }