diff --git a/src/utils/repayment.js b/src/utils/repayment.js index 04cf531..afd2f8c 100644 --- a/src/utils/repayment.js +++ b/src/utils/repayment.js @@ -76,14 +76,18 @@ export function loanSchedule(w, now = currentYm(), cap = 600) { if (fixed > 0) { while (bal > 0 && rows.length < cap) { const interest = Math.round(bal * r) - let principal = fixed - interest - if (principal <= 0) { + if (fixed <= interest) { // 상환금이 이자에 못 미침(데이터 이상) → 더 진행 못함 - rows.push({ label: label(y, m), principal: Math.max(0, principal), interest, total: fixed, balance: bal }) + rows.push({ label: label(y, m), principal: 0, interest, total: fixed, balance: bal }) break } - principal = Math.min(principal, bal) - bal = Math.max(0, bal - principal) + // 마지막 회차: 남은 잔액 한 번에 정산(은행은 잔여 반올림을 마지막 납입에 합산 → 추가 회차 안 생김) + if (bal <= fixed) { + rows.push({ label: label(y, m), principal: bal, interest, total: bal + interest, balance: 0 }) + break + } + const principal = fixed - interest + bal = bal - principal rows.push({ label: label(y, m), principal, interest, total: principal + interest, balance: bal }) ;({ y, m } = addMonths(y, m, 1)) }