- 기존 대출(loanStart 없음)이 남은 회차=전체(60회)로 나오던 문제 수정: 현재 잔액과 최초 상환액으로 남은 개월수 역산(날짜 정보 불필요) - '이번 달 상환' → '이번 달 상환 예정금액', 금액 앞 '이번 달' 제거 - '남은 N회' → '남은 회차 N회' Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+18
-5
@@ -71,19 +71,32 @@ export function loanSchedule(w, now = currentYm(), cap = 600) {
|
||||
}
|
||||
|
||||
// EQUAL_PAYMENT 원리금균등: 매월 상환액 고정
|
||||
if (!nRem) {
|
||||
// 총개월 정보 없음 → 이번 달 이자만 안내(원금 분리 불가)
|
||||
// 남은 개월수는 '현재 잔액 + 최초 상환액'으로 역산 → loanStart 없어도 정확(기존 대출 대응)
|
||||
let n = null
|
||||
let payment = null
|
||||
if (w.loanAmount && w.loanMonths && r > 0) {
|
||||
const origPay = (Number(w.loanAmount) * r) / (1 - Math.pow(1 + r, -Number(w.loanMonths)))
|
||||
payment = Math.round(origPay)
|
||||
// bal = origPay·(1-(1+r)^-n)/r → n = -ln(1 - bal·r/origPay) / ln(1+r)
|
||||
const ratio = 1 - (bal * r) / origPay
|
||||
if (ratio > 0 && ratio < 1) {
|
||||
n = Math.min(Number(w.loanMonths), Math.max(1, Math.ceil(-Math.log(ratio) / Math.log(1 + r) - 1e-9)))
|
||||
}
|
||||
}
|
||||
if (n == null) n = nRem // 잔액 역산 불가 시 loanStart 경과 기반
|
||||
if (n == null) {
|
||||
// 개월·원금 정보 부족 → 이번 달 이자만 안내(원금 분리 불가)
|
||||
const interest = Math.round(bal * r)
|
||||
return {
|
||||
rows: [{ label: label(y, m), principal: null, interest, total: null, balance: bal }],
|
||||
partial: true,
|
||||
}
|
||||
}
|
||||
const payment = r > 0 ? Math.round((bal * r) / (1 - Math.pow(1 + r, -nRem))) : Math.round(bal / nRem)
|
||||
for (let i = 0; i < nRem && bal > 0 && rows.length < cap; i++) {
|
||||
if (payment == null) payment = r > 0 ? Math.round((bal * r) / (1 - Math.pow(1 + r, -n))) : Math.round(bal / n)
|
||||
for (let i = 0; i < n && bal > 0 && rows.length < cap; i++) {
|
||||
const interest = Math.round(bal * r)
|
||||
let principal = payment - interest
|
||||
if (i === nRem - 1 || principal > bal) principal = bal // 마지막 회차 잔액 정산
|
||||
if (i === n - 1 || principal > bal) principal = bal // 마지막 회차 잔액 정산
|
||||
bal = Math.max(0, bal - principal)
|
||||
rows.push({ label: label(y, m), principal, interest, total: principal + interest, balance: bal })
|
||||
;({ y, m } = addMonths(y, m, 1))
|
||||
|
||||
Reference in New Issue
Block a user