${fedCon.notes}
| Consolidated Principal: | ${formatCurrency(fedCon.principal)} |
| New Interest Rate: | ${formatPercent(fedCon.rate / 100)} |
| New Loan Term: | ${fedCon.termYears} years |
| New Monthly Payment: | ${formatCurrency(fedCon.monthlyPayment)} (${formatCurrency(fedCon.monthlyPayment - currentTotalMonthly, true)}) |
| Total Interest Paid: | ${formatCurrency(fedCon.totalInterest)} (${formatCurrency(fedCon.totalInterest - currentTotalInterest, true)}) |
| Total Repaid: | ${formatCurrency(fedCon.totalRepaid)} |
`;
} else {
comparisonHTML += `
${fedCon.notes || "No federal loans to consolidate or data not calculated."}
`;
}
comparisonHTML += `
Private Refinance/Consolidation (Hypothetical)
`;
if (privRefi.principal > 0 && privRefi.monthlyPayment > 0) {
comparisonHTML += `
${privRefi.notes}
| Refinanced Principal: | ${formatCurrency(privRefi.principal)} |
| New Interest Rate: | ${formatPercent(privRefi.rate / 100)} |
| New Loan Term: | ${privRefi.termYears} years |
| Upfront Fees: | ${formatCurrency(privRefi.upfrontFee)} |
| New Monthly Payment: | ${formatCurrency(privRefi.monthlyPayment)} (${formatCurrency(privRefi.monthlyPayment - currentTotalMonthly, true)}) |
| Total Interest Paid: | ${formatCurrency(privRefi.totalInterest)} (${formatCurrency((privRefi.totalInterest + privRefi.upfrontFee) - currentTotalInterest, true)} vs. current interest) |
| Total Cost (Interest + Fees): | ${formatCurrency(privRefi.totalCost)} |
| Total Repaid (incl. Fees): | ${formatCurrency(privRefi.totalRepaid)} |
`;
} else {
comparisonHTML += `
${privRefi.notes || "Private refinance scenario not specified or not applicable."}
`;
}
comparisonHTML += `
Important Considerations:
- Federal Consolidation: Can simplify payments and potentially lower them by extending the term, but may increase total interest paid. It preserves access to federal borrower benefits (like IDR plans, forgiveness). The interest rate is a weighted average rounded up.
- Private Refinancing: May offer a lower interest rate if you have good credit, potentially saving money. However, refinancing federal loans into a private loan means you lose all federal benefits and protections. This is a critical trade-off.
- Extending your loan term generally lowers monthly payments but increases the total interest you'll pay over the life of the loan.
- This calculator provides estimates. Verify all terms with lenders.
`;
if(comparisonOutputEl) comparisonOutputEl.innerHTML = comparisonHTML;
}
if (nextButton) {
nextButton.addEventListener('click', () => {
let canProceed = false;
if (currentTab === 0) { // From Current Loans to Scenarios
canProceed = validateAndStoreTab1();
} else if (currentTab === 1) { // From Scenarios to Summary
canProceed = calculateAndStoreTab2();
if (canProceed) populateComparisonSummary();
}
if (canProceed && currentTab < tabContents.length - 1) {
showTab(currentTab + 1);
}
});
}
if (prevButton) { prevButton.addEventListener('click', () => { if (currentTab > 0) { showTab(currentTab - 1); } }); }
if (tabButtons) {
tabButtons.forEach((button, index) => {
button.addEventListener('click', () => {
if (index < currentTab) { showTab(index); } // Allow going back
else if (index === currentTab) { /* Do nothing */ }
else { // Trying to jump forward
let canReach = true;
for (let i = currentTab; i < index; i++) {
if (i === 0) canReach = validateAndStoreTab1();
else if (i === 1) {
canReach = calculateAndStoreTab2();
if(canReach) populateComparisonSummary();
}
if (!canReach) { showTab(i); if(nextButton) nextButton.click(); break; }
}
if (canReach) showTab(index);
}
});
});
}
if (addLoanButton) { addLoanButton.addEventListener('click', () => addLoanRow()); }
if (downloadPdfButton) {
downloadPdfButton.addEventListener('click', () => {
clearError(errorTab3El);
if (consolidationData.currentLoans.length === 0 || !consolidationData.summary.current) {
displayError(errorTab3El, "Please complete all steps and calculate first."); return;
}
// Ensure PDF libraries are loaded
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') {
displayError(errorTab3El, 'PDF generation library (jsPDF core) is not loaded.'); return;
}
const JSPDFConstructor = window.jspdf.jsPDF;
const doc = new JSPDFConstructor('p', 'pt', 'a4');
if (typeof doc.autoTable !== 'function') {
displayError(errorTab3El, 'PDF table plugin (jsPDF-AutoTable) is not functional.'); return;
}
let finalY = 40;
const pageWidth = doc.internal.pageSize.getWidth();
const margin = 40;
doc.setFontSize(16);
doc.text("Student Loan Consolidation Comparison", pageWidth / 2, finalY, { align: 'center' });
finalY += 25;
doc.setFontSize(11);
doc.text("Current Loans Entered:", margin, finalY);
finalY += 5;
const currentLoansTableHead = [["Loan Name", "Type", "Balance ($)", "Rate (%)", "Term (Yrs)", "Monthly Pmt ($)"]];
const currentLoansTableBody = consolidationData.currentLoans.map(l => [l.name, l.type, l.balance.toFixed(2), l.rate.toFixed(3), l.term.toFixed(1), l.monthlyPayment.toFixed(2)]);
doc.autoTable({ head: currentLoansTableHead, body: currentLoansTableBody, startY: finalY, theme: 'grid', headStyles: {fillColor: [0,115,170], fontSize:9}, styles: {fontSize: 8, cellPadding:3} });
finalY = doc.lastAutoTable.finalY + 15;
const summaryTableHead = [["Metric", "Current Total", "Federal Consolidation", "Private Refinance (Optional)"]];
const summaryTableBody = [
["Total Principal", formatCurrency(consolidationData.summary.current.balance), formatCurrency(consolidationData.federalConsolidation.principal), formatCurrency(consolidationData.privateRefinance.principal)],
["Interest Rate", "Weighted Avg: N/A*", formatPercent(consolidationData.federalConsolidation.rate/100), consolidationData.privateRefinance.rate > 0 ? formatPercent(consolidationData.privateRefinance.rate/100) : "N/A"],
["Loan Term (Years)", "Varies*", consolidationData.federalConsolidation.termYears, consolidationData.privateRefinance.termYears > 0 ? consolidationData.privateRefinance.termYears : "N/A"],
["Monthly Payment", formatCurrency(consolidationData.summary.current.monthlyPayment), formatCurrency(consolidationData.federalConsolidation.monthlyPayment), consolidationData.privateRefinance.monthlyPayment > 0 ? formatCurrency(consolidationData.privateRefinance.monthlyPayment) : "N/A"],
["Total Interest Paid", formatCurrency(consolidationData.summary.current.totalInterest), formatCurrency(consolidationData.federalConsolidation.totalInterest), consolidationData.privateRefinance.totalCost > 0 ? formatCurrency(consolidationData.privateRefinance.totalInterest) : "N/A"],
["Total Fees (Consolidation)", "N/A", "$0.00 (Federal)", consolidationData.privateRefinance.upfrontFee > 0 ? formatCurrency(consolidationData.privateRefinance.upfrontFee) : "$0.00"],
["Total Repaid", formatCurrency(consolidationData.summary.current.totalRepaid), formatCurrency(consolidationData.federalConsolidation.totalRepaid), consolidationData.privateRefinance.totalRepaid > 0 ? formatCurrency(consolidationData.privateRefinance.totalRepaid) : "N/A"]
];
if (finalY > doc.internal.pageSize.getHeight() - 150) { doc.addPage(); finalY = 40; }
doc.setFontSize(11);
doc.text("Consolidation Scenarios Summary:", margin, finalY);
finalY += 5;
doc.autoTable({ head: summaryTableHead, body: summaryTableBody, startY: finalY, theme: 'grid', headStyles: {fillColor: [0,115,170], fontSize:9}, styles: {fontSize: 8, cellPadding:3} });
finalY = doc.lastAutoTable.finalY + 10;
doc.setFontSize(7);
doc.text("* Current loans' weighted average rate and combined term are complex to average meaningfully if terms differ; totals are sums.", margin, finalY);
finalY += 15;
if (finalY > doc.internal.pageSize.getHeight() - 100) { doc.addPage(); finalY = 40; }
doc.setFontSize(10);
doc.text("Important Notes:", margin, finalY);
finalY += 12;
doc.setFontSize(8);
const notes = [
"- Federal Consolidation: Rate is weighted average of consolidated federal loans, rounded up to nearest 1/8th %. Extends term, may lower payment but increase total interest. Preserves federal benefits.",
"- Private Refinance: Rate based on credit. Can include federal & private loans. Refinancing federal loans means losing federal benefits (IDR, forgiveness). Fees may apply.",
"- This calculator provides estimates. Actual terms vary. This is not financial advice."
];
notes.forEach(note => {
const splitNote = doc.splitTextToSize(note, pageWidth - 2 * margin);
doc.text(splitNote, margin, finalY);
finalY += splitNote.length * 9 + 3; // Dynamic line height
if (finalY > doc.internal.pageSize.getHeight() - 30) { doc.addPage(); finalY = 40; }
});
doc.save("Student_Loan_Consolidation_Estimate.pdf");
});
}
// Initialize with one loan row
addLoanRow(true);
showTab(0);
});