Estimated Cost Difference
${costDifference > 0 ?
`
The Credit Union loan could be $${costDifference.toFixed(2)} CHEAPER overall.
` :
costDifference < 0 ?
`
The Bank loan could be $${Math.abs(costDifference).toFixed(2)} CHEAPER overall.
` :
`
Both loan options have the same estimated total cost based on your inputs.
`}
`;
resultsOutputEl.innerHTML = outputHTML;
}
function cuvbDownloadPDF() {
if (!cuvbLastAnalysisData) {
alert("Please analyze costs first.");
cuvbNavigateTab('cuvbComparisonTab'); cuvbAnalyzeCosts();
if (!cuvbLastAnalysisData) return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
const { inputs, creditUnion, bank, difference } = cuvbLastAnalysisData;
const primaryColor = [0, 121, 107];
let y = 15;
doc.setFontSize(16); doc.setTextColor(primaryColor[0], primaryColor[1], primaryColor[2]);
doc.text("Credit Union vs. Bank Loan Cost Analysis", doc.internal.pageSize.getWidth() / 2, y, { align: 'center' });
y += 8;
doc.setFontSize(8); doc.setTextColor(100);
doc.text("Illustrative comparison based on user inputs. Not financial advice.", doc.internal.pageSize.getWidth() / 2, y, { align: 'center' });
y += 10;
doc.setFontSize(11); doc.setTextColor(51, 51, 51);
doc.text("Common Loan Details:", 14, y); y += 6;
doc.setFontSize(10);
doc.text(` Loan Amount: $${inputs.loanAmount.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}`, 14, y);
doc.text(`Loan Term: ${inputs.loanTermYears} years`, 100, y); y += 8;
const addLenderDetailsToPdf = (lenderName, details, rate, fees) => {
doc.setFontSize(11); doc.setTextColor(primaryColor[0], primaryColor[1], primaryColor[2]);
doc.text(`${lenderName} Offer:`, 14, y); y += 6;
doc.setFontSize(10); doc.setTextColor(51,51,51);
doc.text(` Interest Rate: ${rate.toFixed(2)}%`, 14, y);
doc.text(`Upfront Fees: $${fees.toFixed(2)}`, 100, y);y += 5;
doc.text(` Est. Monthly Payment: $${details.monthlyPayment.toFixed(2)}`, 14, y); y += 5;
doc.text(` Total Interest Paid: $${details.totalInterest.toFixed(2)}`, 14, y); y += 5;
doc.text(` Total Principal Paid: $${details.totalPrincipal.toFixed(2)}`, 14, y); y += 5;
doc.setFont(undefined, 'bold');
doc.text(` Total Estimated Cost: $${details.totalCost.toFixed(2)}`, 14, y); y += 8;
doc.setFont(undefined, 'normal');
};
addLenderDetailsToPdf("Credit Union", creditUnion, inputs.cuRate, inputs.cuFees);
if (y > 200) { doc.addPage(); y = 20; }
addLenderDetailsToPdf("Bank", bank, inputs.bankRate, inputs.bankFees);
if (y > 240) { doc.addPage(); y = 20; }
doc.setFontSize(12); doc.setTextColor(primaryColor[0], primaryColor[1], primaryColor[2]);
doc.text("Estimated Cost Difference:", 14, y); y += 7;
doc.setFontSize(12); doc.setFont(undefined, 'bold');
if (difference > 0) {
doc.setTextColor(39, 174, 96); // Green
doc.text(`The Credit Union loan could be $${difference.toFixed(2)} CHEAPER overall.`, 14, y);
} else if (difference < 0) {
doc.setTextColor(39, 174, 96); // Green (Bank is cheaper)
doc.text(`The Bank loan could be $${Math.abs(difference).toFixed(2)} CHEAPER overall.`, 14, y);
} else {
doc.setTextColor(51,51,51);
doc.text("Both options have the same estimated total cost.", 14, y);
}
y += 10;
doc.setFont(undefined, 'normal');
if (y > 250) { doc.addPage(); y = 20; }
doc.setFontSize(9); doc.setTextColor(85, 85, 85);
const advisoryTitle = "Understanding Your Loan Cost Comparison:";
const advisoryContent = [
"Estimates are based solely on your inputs. Actual rates, APRs, and fees vary.",
"Credit unions (non-profit, member-owned) may sometimes offer lower rates/fees than for-profit banks, but compare specific offers.",
"Credit unions have membership requirements (employer, location, etc.).",
"Always compare official Loan Estimates or loan disclosures from multiple institutions, focusing on APR, total interest, fees, and total loan cost."
];
doc.setFont(undefined, 'bold'); doc.text(advisoryTitle, 14, y); y +=5;
doc.setFont(undefined, 'normal');
advisoryContent.forEach(line => {
const splitLine = doc.splitTextToSize(`• ${line}`, doc.internal.pageSize.getWidth() - 28 - 5);
doc.text(splitLine, 14, y);
y += (splitLine.length * 4) + 1;
if (y > 270 && advisoryContent.indexOf(line) < advisoryContent.length -1) { doc.addPage(); y = 20; }
});
y+=3;
doc.setFontSize(8); doc.setFont(undefined, 'italic'); doc.setTextColor(100);
doc.text("This tool is for educational purposes and not financial advice.", 14, y);
doc.save("CreditUnion_vs_Bank_Loan_Cost.pdf");
}
cuvbUpdateNavButtons();
window.cuvbSwitchTab = cuvbSwitchTab;
window.cuvbNavigateTab = cuvbNavigateTab;
window.cuvbAnalyzeCosts = cuvbAnalyzeCosts;
window.cuvbDownloadPDF = cuvbDownloadPDF;