Retirement Savings Planner

Retirement Savings Planner

Project your savings growth and see if you're on track for retirement.

Your Financial Profile

Personal Details

Savings & Contributions

Assumptions

Retirement Readiness Analysis

Projected Savings Growth

${statusText}

`; renderChart(chartData); } const createKpiCard = (label, value) => `

${label}

${value}

`; function renderChart(chartData) { if (savingsChart) savingsChart.destroy(); savingsChart = new Chart(document.getElementById('savings-chart'), { type: 'line', data: chartData, options: { scales: { x: { title: { display: true, text: 'Age' } }, y: { title: { display: true, text: 'Savings ($)' }, ticks: { callback: value => '$' + (value/1000) + 'k' } } } } }); } // --- PDF GENERATION --- async function generatePdfReport() { const result = state.analysisResult; if (!result) return alert("Please run an analysis first."); downloadPdfBtn.disabled = true; downloadPdfBtn.textContent = 'Generating...'; const chartImg = savingsChart.toBase64Image(); const { kpis, status } = result; const reportHtml = `

Retirement Readiness Report

Prepared on ${new Date().toLocaleDateString('en-US', { dateStyle: 'long' })}

Key Projections

Projected Nest Egg
$${kpis.projectedNestEgg.toLocaleString('en-US', {maximumFractionDigits: 0})}
Required Nest Egg
$${kpis.requiredNestEgg.toLocaleString('en-US', {maximumFractionDigits: 0})}
${status === 'On Track' ? 'Surplus' : 'Shortfall'}
$${Math.abs(kpis.shortfall).toLocaleString('en-US', {maximumFractionDigits: 0})}

Your Retirement Status

YOU ARE ${status === 'On Track' ? 'ON TRACK' : 'FACING A SHORTFALL'}
${status === 'On Track' ? `You have a projected surplus of $${Math.abs(kpis.shortfall).toLocaleString('en-US', {maximumFractionDigits: 0})}.` : `You have a projected shortfall of $${Math.abs(kpis.shortfall).toLocaleString('en-US', {maximumFractionDigits: 0})}.`}

Projected Growth Trajectory

`; const pdfTemplate = document.getElementById('pdf-template'); pdfTemplate.innerHTML = reportHtml; pdfTemplate.classList.remove('invisible'); try { const { jsPDF } = window.jspdf; const canvas = await html2canvas(pdfTemplate.querySelector('.pdf-report-container'), { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); pdf.addImage(imgData, 'PNG', 0, 0, pdf.internal.pageSize.getWidth(), (canvas.height * pdf.internal.pageSize.getWidth()) / canvas.width); pdf.save(`Retirement_Readiness_Report.pdf`); } catch(e) { console.error('PDF Generation Error:', e); } finally { downloadPdfBtn.disabled = false; downloadPdfBtn.textContent = 'Download Readiness Report'; pdfTemplate.classList.add('invisible'); } } downloadPdfBtn.addEventListener('click', generatePdfReport); // --- INITIALIZATION --- runAnalysis(); switchTab(0); });
Scroll to Top