';
// Savings boxes
if (r.interestSavings > 0) {
html += '
';
// Chart canvas
html += '';
// Amortization toggle
html += '';
html += '';
html += '
';
container.innerHTML = html;
// Store result for PDF export
window['result_' + containerId] = r;
// Draw chart
setTimeout(function() { drawChart(canvasId, r); }, 50);
}
// ===== AMORTIZATION TABLE =====
function renderAmortTable(original, withPayoff, tableId) {
var maxLen = Math.max(original.length, withPayoff.length);
var totalYears = Math.ceil(maxLen / 12);
var html = '';
html += '';
html += '';
html += '
';
}
// Comparison table
html += 'Interest savings
' + formatCurrency(r.interestSavings) + '
';
html += 'Original: ' + formatCurrency(r.originalRemainingInterest) + '
With payoff: ' + formatCurrency(r.newRemainingInterest) + '
Pay ' + iSavPct + '% less on interest
With payoff: ' + formatCurrency(r.newRemainingInterest) + '
Pay ' + iSavPct + '% less on interest
Time savings
' + formatMonths(r.timeSavingsMonths) + '
';
html += 'Original: ' + formatMonths(r.originalSchedule.length) + '
With payoff: ' + formatMonths(r.newSchedule.length) + '
Payoff ' + tSavPct + '% faster
With payoff: ' + formatMonths(r.newSchedule.length) + '
Payoff ' + tSavPct + '% faster
| Original | With payoff | |
|---|---|---|
| ' + rows[i][0] + ' | ' + rows[i][1] + ' | ' + rows[i][2] + ' |
â–¶View Amortization Table
Click to expand| Original (without payoff) | With payoff | |||||
|---|---|---|---|---|---|---|
| Interest | Principal | Balance | Interest | Principal | Balance | |
| Year ' + year + ' | '; html += '' + (oe.length > 0 ? formatCurrencyDecimal(oInt) : '-') + ' | '; html += '' + (oe.length > 0 ? formatCurrencyDecimal(oPrin) : '-') + ' | '; html += '' + (oe.length > 0 ? formatCurrencyDecimal(oBal) : '-') + ' | '; html += '' + (ne.length > 0 ? formatCurrencyDecimal(nInt) : '-') + ' | '; html += '' + (ne.length > 0 ? formatCurrencyDecimal(nPrin) : '-') + ' | '; html += '' + (ne.length > 0 ? formatCurrencyDecimal(nBal) : '-') + ' | '; html += '
Click Calculate to see results
';
}
function clearUnknown() {
document.getElementById('u-principal').value = '';
document.getElementById('u-monthlyPayment').value = '';
document.getElementById('u-interestRate').value = '';
document.getElementById('u-extraAmount').value = '';
document.getElementById('u-results').innerHTML = 'Click Calculate to see results
';
}
// ===== PDF EXPORT =====
function exportPDF(containerId, title) {
var r = window['result_' + containerId];
if (!r) return;
var jsPDF = window.jspdf.jsPDF;
var doc = new jsPDF();
doc.setFontSize(18);
doc.setFont('helvetica', 'bold');
doc.text('Mortgage Payoff Calculator Results', 105, 20, { align: 'center' });
doc.setFontSize(12);
doc.setTextColor(90, 154, 58);
doc.text(title, 105, 30, { align: 'center' });
doc.setFontSize(14);
doc.text('Payoff in ' + formatMonths(r.newPayoffMonths), 105, 42, { align: 'center' });
doc.setTextColor(0, 0, 0);
doc.setFontSize(11);
doc.setFont('helvetica', 'normal');
var y = 55;
if (r.interestSavings > 0) {
doc.text('Interest Savings: ' + formatCurrency(r.interestSavings), 20, y); y += 7;
doc.text('Time Savings: ' + formatMonths(r.timeSavingsMonths), 20, y); y += 12;
}
doc.setFont('helvetica', 'bold');
doc.text('Comparison', 20, y); y += 8;
doc.text('', 25, y);
doc.text('Original', 120, y);
doc.text('With Payoff', 165, y); y += 7;
doc.setFont('helvetica', 'normal');
var pdfRows = [
['Monthly pay', formatCurrencyDecimal(r.originalMonthlyPayment), formatCurrencyDecimal(r.newMonthlyPayment)],
['Total payments', formatCurrencyDecimal(r.originalTotalPayments), formatCurrencyDecimal(r.newTotalPayments)],
['Total interest', formatCurrencyDecimal(r.originalTotalInterest), formatCurrencyDecimal(r.newTotalInterest)],
['Remaining payments', formatCurrencyDecimal(r.originalRemainingPayments), formatCurrencyDecimal(r.newRemainingPayments)],
['Remaining interest', formatCurrencyDecimal(r.originalRemainingInterest), formatCurrencyDecimal(r.newRemainingInterest)],
['Payoff in', formatMonths(r.originalSchedule.length), formatMonths(r.newSchedule.length)]
];
pdfRows.forEach(function(row) {
doc.text(row[0], 25, y);
doc.text(row[1], 120, y);
doc.text(row[2], 165, y);
y += 7;
});
doc.setFontSize(9);
doc.setTextColor(150, 150, 150);
doc.text('Generated on ' + new Date().toLocaleString(), 105, 280, { align: 'center' });
doc.save('mortgage-payoff-' + new Date().toISOString().split('T')[0] + '.pdf');
}
