private static void InvoiceEvent(Loan loan, LoanEvent loanEvent) { var firstDayOfMonth = new DateTime(loanEvent.EventTime.Year, loanEvent.EventTime.Month, 1); var firstDayOfNextMonth = firstDayOfMonth.AddMonths(1); loan.AddInvoice(loanEvent.EventTime, firstDayOfMonth, firstDayOfNextMonth, loanEvent.Amount); }
private List <LoanPayment> CreateLoanPaymentPlan(Loan loan, bool addSinglePayment = false) { // 4 year, 10 percentage, 16000 principal. Gives 0.05 left after 4 years. What is the worst outcome? // 1 year, 10 percentage, 10000 principal. Gives a ton of rounding errors. Have to be fixed with rounding in both setting rate, principal, and total. var invoices = new List <LoanPayment>(); var baseDate = loan.PayoutDate; Invoice tmp = null; while (loan.CurrentPrincipal >= 0.01) { baseDate = baseDate.AddMonths(1); var date = baseDate.AddDays(-1); var invoice = loan.AddInvoice(date, new DateTime(date.Year, date.Month, 1), baseDate, 0.0); loan.CurrentPrincipal -= invoice.Principal; if (addSinglePayment && invoices.Count() == 5) { var p = invoice.Pay(invoice.InvoiceDate, invoice.Principal / 2); invoice.Principal -= p.Principal + p.Reminder; invoice.Interest -= p.Interest; invoice.LateFee -= p.LateFee; } invoices.Add(new LoanPayment { PeriodFormatted = invoice.InvoiceDate.ToString("yyyy-MM-dd"), Principal = invoice.Principal, Interest = invoice.Interest, }); tmp = invoice; } //var q = invoices.Sum(s => s.Principal); //var w = invoices.Sum(s => s.Interest); //var e = tmp.Principal; //var f = tmp.Interest; return(invoices); }