Use first payment date and maturity date instead of origination date and term
Replace the term months field with a maturity date picker - users know when their loan ends, not the month count. Compute termMonths from the two dates. Rename "Origination Date" to "First Payment Date" and adjust the amortization schedule so payment #1 falls on the entered date. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -665,20 +665,21 @@ public class BankSyncService : IBankSyncService
|
||||
var originalBalance = liability.OriginalBalance ?? Math.Abs(linked.LastKnownBalance ?? 0);
|
||||
var interestRate = liability.InterestRate ?? 0;
|
||||
var termMonths = liability.TermMonths ?? (liability.LoanType == "Mortgage" ? 360 : 60);
|
||||
var originationDate = liability.OriginationDate ?? DateTime.UtcNow;
|
||||
// Plaid gives loan origination date; first payment is typically one month later
|
||||
var firstPaymentDate = liability.OriginationDate?.AddMonths(1) ?? DateTime.UtcNow;
|
||||
var escrowBalance = liability.EscrowBalance;
|
||||
|
||||
// Compute monthly payment via amortization formula if not provided
|
||||
var monthlyPayment = liability.MonthlyPayment ?? ComputeMonthlyPayment(originalBalance, interestRate, termMonths);
|
||||
|
||||
var maturityDate = liability.MaturityDate ?? originationDate.AddMonths(termMonths);
|
||||
var maturityDate = liability.MaturityDate ?? firstPaymentDate.AddMonths(termMonths - 1);
|
||||
|
||||
var request = new CreateLoanDetailRequest(
|
||||
originalBalance,
|
||||
interestRate,
|
||||
termMonths,
|
||||
monthlyPayment,
|
||||
DateTime.SpecifyKind(originationDate, DateTimeKind.Utc),
|
||||
DateTime.SpecifyKind(firstPaymentDate, DateTimeKind.Utc),
|
||||
DateTime.SpecifyKind(maturityDate, DateTimeKind.Utc),
|
||||
escrowBalance,
|
||||
null
|
||||
|
||||
@@ -187,11 +187,11 @@ public class LoanService : ILoanService
|
||||
var dailyRate = loan.InterestRate / 100m / 365m;
|
||||
var payment = loan.MonthlyPayment - (loan.EscrowAmount ?? 0);
|
||||
var extra = loan.ExtraPayment ?? 0;
|
||||
var previousDate = loan.OriginationDate;
|
||||
var previousDate = loan.OriginationDate.AddMonths(-1);
|
||||
|
||||
for (int i = 1; i <= loan.TermMonths && balance > 0; i++)
|
||||
{
|
||||
var paymentDate = loan.OriginationDate.AddMonths(i);
|
||||
var paymentDate = loan.OriginationDate.AddMonths(i - 1);
|
||||
var days = (paymentDate - previousDate).Days;
|
||||
var interest = balance * dailyRate * days;
|
||||
var principal = Math.Min(payment + extra - interest, balance);
|
||||
|
||||
Reference in New Issue
Block a user