fix: apply last-row rounding correction to Excel export

This commit is contained in:
Nut.ไปเรื่อย
2026-05-28 12:59:11 +07:00
parent 43e37df39f
commit 4e51959fa6
@@ -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]);
});