From 4e51959fa6c5df843e3a25ab02c9afa18b4e13db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nut=2E=E0=B9=84=E0=B8=9B=E0=B9=80=E0=B8=A3=E0=B8=B7?= =?UTF-8?q?=E0=B9=88=E0=B8=AD=E0=B8=A2?= Date: Thu, 28 May 2026 12:59:11 +0700 Subject: [PATCH] fix: apply last-row rounding correction to Excel export --- construction-installment-calculator/index.html | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/construction-installment-calculator/index.html b/construction-installment-calculator/index.html index 6cdd2bd..84cc542 100644 --- a/construction-installment-calculator/index.html +++ b/construction-installment-calculator/index.html @@ -454,13 +454,16 @@ function exportExcel() { let cumDays = 0, cumTotal = 0, cumNgpm = 0, cumNook = 0; installments.forEach((inst, i) => { - const days = parseFloat(inst.days) || 0; - const pct = parseFloat(inst.percent) || 0; + const days = parseFloat(inst.days) || 0; + const pct = parseFloat(inst.percent) || 0; + const isLast = i === installments.length - 1; cumDays += days; - const total = Math.round(contract * pct / 100); - const ngpm = Math.round(total * ngpmPct / 100); - const nook = total - ngpm; + + const total = isLast ? (contract - cumTotal) : Math.round(contract * pct / 100); + const ngpm = isLast ? (Math.round(contract * ngpmPct / 100) - cumNgpm) : Math.round(total * ngpmPct / 100); + const nook = total - ngpm; cumTotal += total; cumNgpm += ngpm; cumNook += nook; + const delivery = toThaiDate(addDays(startDate, cumDays)); rows.push([i+1, days, pct, delivery, total, ngpm, nook, cumTotal, cumNgpm, cumNook]); });