Assumed Tuition Loan Term:${tflac_loanData.termYears} years
Tuition Loan Affordability Estimate
${M <= 0 && P_affordable <= 0 ? '
Based on your inputs, there is no budget for an additional tuition loan payment.
' : ''}
Estimated TUITION Loan Amount You Might Afford:${tflac_formatCurrency(tflac_loanData.affordableLoanAmount)}
Total You'd Pay for this Tuition Loan:${tflac_formatCurrency(tflac_loanData.totalRepaidForTuitionLoan)}
Total Interest for this Tuition Loan:${tflac_formatCurrency(tflac_loanData.totalInterestForTuitionLoan)}
Important Note: This calculator provides an estimate to guide your financial planning for tuition fees. Your actual borrowing capacity will depend on a lender's specific criteria, your complete financial profile, and prevailing market conditions.
Always consider the total cost of attendance (tuition, fees, living expenses) and subtract any scholarships, grants, or personal savings to determine your actual borrowing needs. This estimate is for the remaining gap. It's advisable to borrow conservatively.
`;
}
if (tflac_domElements.pdfDownloadBtn) {
// Show PDF button if calculation was attempted, even if amount is 0.
tflac_domElements.pdfDownloadBtn.classList.remove('tflac-hidden');
}
}
function tflac_hexToRgb(hex) {
if (!hex || typeof hex !== 'string') return null;
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function(m, r, g, b) { return r + r + g + g + b + b; });
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : null;
}
function tflac_generatePdf() {
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined' || typeof window.jspdf.jsPDF.API === 'undefined' || typeof window.jspdf.jsPDF.API.autoTable === 'undefined') {
alert("PDF generation library is not loaded. Please try again later."); return;
}
if (!tflac_validateTab1() || !tflac_validateTab2()) {
alert("Please ensure all inputs are correctly filled before generating PDF.");
if (!tflac_validateTab1()) tflac_navigateToTab('tflac-tab1');
else if (!tflac_validateTab2()) tflac_navigateToTab('tflac-tab2');
return;
}
tflac_calculateAndDisplayAffordability();
if (tflac_domElements.resultsContainer && tflac_domElements.resultsContainer.innerHTML.includes("tflac-error-message")) {
alert("Cannot generate PDF due to errors in input or calculation. Please correct them."); return;
}
const ActualJsPDF = window.jspdf.jsPDF;
const doc = new ActualJsPDF();
const { annualSalary, otherMonthlyDebts, totalIncomePercentageForDebts, grossMonthlyIncome,
affordableMonthlyForTuitionLoan, interestRate, termYears,
affordableLoanAmount, totalRepaidForTuitionLoan, totalInterestForTuitionLoan } = tflac_loanData;
doc.setFontSize(18);
const primaryColorRGB = tflac_hexToRgb(getComputedStyle(document.documentElement).getPropertyValue('--tflac-primary-color').trim());
const secondaryColorRGB = tflac_hexToRgb(getComputedStyle(document.documentElement).getPropertyValue('--tflac-secondary-color').trim());
const accentColorRGB = tflac_hexToRgb(getComputedStyle(document.documentElement).getPropertyValue('--tflac-accent-color').trim());
if (primaryColorRGB) doc.setTextColor(primaryColorRGB.r, primaryColorRGB.g, primaryColorRGB.b); else doc.setTextColor(74,144,226);
doc.text("Tuition Fee Loan Affordability Estimate", 105, 22, null, null, "center");
doc.setFontSize(12);
doc.setTextColor(51,51,51);
let startY = 35;
const tableHeadFillColor = secondaryColorRGB ? [secondaryColorRGB.r, secondaryColorRGB.g, secondaryColorRGB.b] : [53,122,189];
doc.setFontSize(13);
if (secondaryColorRGB) doc.setTextColor(secondaryColorRGB.r, secondaryColorRGB.g, secondaryColorRGB.b); else doc.setTextColor(53,122,189);
doc.text("Your Financial Snapshot & Assumptions", 14, startY); startY += 8;
doc.autoTable({
startY: startY, theme: 'grid', headStyles: { fillColor: tableHeadFillColor, textColor: 255 },
body: [
["Est. Annual Post-Grad Salary:", tflac_formatCurrency(annualSalary)],
["Est. Gross Monthly Income:", tflac_formatCurrency(grossMonthlyIncome)],
["Other Monthly Debt Payments:", tflac_formatCurrency(otherMonthlyDebts)],
["Income % for All Loan Payments:", tflac_formatPercent(totalIncomePercentageForDebts)],
["Affordable Monthly for NEW Tuition Loan:", tflac_formatCurrency(affordableMonthlyForTuitionLoan)],
["Assumed Tuition Loan Interest Rate:", tflac_formatPercent(interestRate, 2)],
["Assumed Tuition Loan Term:", `${termYears} years`],
], margin: { left: 14, right: 14 },
styles: { fontSize: 9.5, cellPadding: 2 }, headStyles: { fontSize: 10, cellPadding: 2 }
});
startY = doc.autoTable.previous.finalY + 10;
doc.setFontSize(13);
if (secondaryColorRGB) doc.setTextColor(secondaryColorRGB.r, secondaryColorRGB.g, secondaryColorRGB.b); else doc.setTextColor(53,122,189);
doc.text("Tuition Loan Affordability Estimate", 14, startY); startY += 8;
let affordabilityBodyPDF = [
[{content: "Estimated TUITION Loan Amount You Might Afford:", styles: {fontStyle: 'bold'}},
{content: tflac_formatCurrency(affordableLoanAmount), styles: {fontStyle: 'bold', fontSize: 10, textColor: accentColorRGB ? [accentColorRGB.r, accentColorRGB.g, accentColorRGB.b] : [80,227,194]}}],
["Total You'd Pay for this Tuition Loan:", tflac_formatCurrency(totalRepaidForTuitionLoan)],
["Total Interest for this Tuition Loan:", tflac_formatCurrency(totalInterestForTuitionLoan)],
];
if (affordableMonthlyForTuitionLoan <= 0 && affordableLoanAmount <= 0) {
affordabilityBodyPDF.unshift([{content: "Based on your inputs, there is no room for an additional tuition loan payment.", colSpan: 2, styles: {halign: 'center', textColor: [217,83,79], fontSize: 9}}]);
}
doc.autoTable({
startY: startY, theme: 'grid', headStyles: { fillColor: tableHeadFillColor, textColor: 255 },
body: affordabilityBodyPDF, margin: { left: 14, right: 14 },
styles: { fontSize: 9.5, cellPadding: 2 }, headStyles: { fontSize: 10, cellPadding: 2 }
});
startY = doc.autoTable.previous.finalY + 12;
doc.setFontSize(10);
doc.setTextColor(51,51,51);
doc.text("Important Note:", 14, startY); startY += 6;
doc.setFontSize(8.5);
const guidance1 = "This calculator provides an estimate to guide your financial planning for tuition fees. Your actual borrowing capacity will depend on a lender's specific criteria, your complete financial profile, and prevailing market conditions.";
const guidance2 = "Always consider the total cost of attendance (tuition, fees, living expenses) and subtract any scholarships, grants, or personal savings to determine your actual borrowing needs. This estimate is for the remaining gap. It's advisable to borrow conservatively.";
const splitGuidance1 = doc.splitTextToSize(guidance1, doc.internal.pageSize.width - 28);
doc.text(splitGuidance1, 14, startY);
startY += (splitGuidance1.length * (doc.getLineHeight() / doc.internal.scaleFactor * 0.85)) + 3;
const splitGuidance2 = doc.splitTextToSize(guidance2, doc.internal.pageSize.width - 28);
doc.text(splitGuidance2, 14, startY);
doc.setFontSize(9);
doc.setTextColor(120);
doc.text(`Report generated on: ${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}`, 14, doc.internal.pageSize.height - 10);
doc.save("Tuition_Fee_Loan_Affordability_Estimate.pdf");
}
window.tflac_updateMonthlyIncomeDisplay = tflac_updateMonthlyIncomeDisplay;
window.tflac_updateAffordableForTuitionLoanDisplay = tflac_updateAffordableForTuitionLoanDisplay;
window.tflac_switchTab = tflac_switchTab;
window.tflac_navigateToTab = tflac_navigateToTab;
window.tflac_generatePdf = tflac_generatePdf;