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]); });