diff --git a/src/views/account/AccountView.vue b/src/views/account/AccountView.vue index 137574c..6641711 100644 --- a/src/views/account/AccountView.vue +++ b/src/views/account/AccountView.vue @@ -173,13 +173,23 @@ const loanAutoResult = computed(() => { const principal = Math.round(Number(loan.loanAmount) / loan.loanMonths) return { interest, principal, total: principal + interest, needsInput: false } } - if (loan.loanMethod === 'EQUAL_PAYMENT' && loan.loanAmount && loan.loanMonths && loan.loanRate) { - // PMT 공식: M = P × r(1+r)^n / ((1+r)^n − 1) - const r = Number(loan.loanRate) / 100 / 12 - const n = loan.loanMonths - const M = Math.round(Number(loan.loanAmount) * r * Math.pow(1 + r, n) / (Math.pow(1 + r, n) - 1)) - const principal = Math.max(0, M - interest) - return { interest, principal, total: M, needsInput: false } + if (loan.loanMethod === 'EQUAL_PAYMENT') { + // 월 상환금이 저장돼 있으면 그대로 사용(은행과 일치) → 없으면 원금·개월수로 PMT 추정 + let M = null + if (loan.loanPayment) { + M = Number(loan.loanPayment) + } else if (loan.loanAmount && loan.loanMonths && loan.loanRate) { + // PMT 공식: M = P × r(1+r)^n / ((1+r)^n − 1) + const r = Number(loan.loanRate) / 100 / 12 + const n = loan.loanMonths + M = Math.round(Number(loan.loanAmount) * r * Math.pow(1 + r, n) / (Math.pow(1 + r, n) - 1)) + } + if (M != null) { + // 마지막 회차 등 잔액이 작을 땐 원금을 잔액까지만(초과 상환 방지) + const bal = Math.abs(Number(loan.balance) || 0) + const principal = Math.min(Math.max(0, M - interest), bal) + return { interest, principal, total: principal + interest, needsInput: false } + } } return { interest: null, principal: null, total: null, needsInput: true } })