fix(repayment): 원리금균등 마지막 회차에 잔여 반올림 합산 — 꼬리 회차 제거
Deploy / deploy (push) Failing after 14m27s

- 매월 이자 반올림 누적으로 마지막 정상 회차 뒤 수십원(원금 62·이자 1) 추가 회차
  생기던 문제. 잔액<=월상환금이면 마지막 회차로 남은 잔액을 한 번에 정산(은행 동일)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
sb
2026-07-07 23:22:02 +09:00
parent 18f015f7fd
commit a5264f4dff
+9 -5
View File
@@ -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))
}