Savings Growth & Compound Interest Calculator
Step 1: Enter Your Savings & Investment Details
Step 2: Your Savings Growth Projection
Enter details on Tab 1 and click "Calculate Growth Projection".
Year-by-Year Growth Breakdown:
Total Interest Earned: $${totalInterestEarned.toFixed(2)}
${annualInflationRate > 0 ? `
Future Value in Today's Dollars (Real Value): $${sgrReportData.results.realFutureValue.toFixed(2)}
` : ''}
`;
displayYearlyTable(yearlyBreakdown, annualInflationRate > 0);
document.getElementById('downloadSavingsPdfButton').disabled = false;
if (autoNavigate && currentSGRTabIndex === 0) {
openSGRTab(null, 'projectionSGRTab');
}
}
function displayYearlyTable(yearlyData, showRealValue) {
const tableContainer = document.getElementById('sgrProjectionTableContainer');
const table = document.getElementById('sgrYearlyTable');
if (!yearlyData || yearlyData.length === 0) {
tableContainer.style.display = 'none';
return;
}
let headHTML = `
| Year | Start Balance ($) | Contributions ($) | Interest Earned ($) | End Balance ($) | `;
if (showRealValue) {
headHTML += `End Balance (Today's $) | `;
}
headHTML += `
|---|
`;
let bodyHTML = "";
yearlyData.forEach(row => {
bodyHTML += `
| ${row.year} |
${row.startingBalance.toFixed(2)} |
${row.contributions.toFixed(2)} |
${row.interest.toFixed(2)} |
${row.endingBalance.toFixed(2)} |
${showRealValue && row.realValueEndingBalance !== null ? `${row.realValueEndingBalance.toFixed(2)} | ` : (showRealValue ? 'N/A | ' : '')}
`;
});
table.innerHTML = `
${headHTML}${bodyHTML}`;
tableContainer.style.display = 'block';
}
function downloadSGRPdf() {
if (Object.keys(sgrReportData).length === 0 || !sgrReportData.results) {
alert("Please calculate the projection first."); return;
}
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') {
alert('PDF generation library (jsPDF) is not loaded.'); return;
}
const jsPDFConstructor = window.jspdf.jsPDF;
const doc = new jsPDFConstructor();
if (typeof doc.autoTable !== 'function') {
alert('jsPDF AutoTable plugin not loaded.'); return;
}
const { inputs, results } = sgrReportData;
const primaryColor = '#007bff', textColor = '#212529', tableHeaderColor = '#e9ecef';
let yPos = 22;
const pageHeight = doc.internal.pageSize.height; const margin = 20;
function checkYPdf(increment = 10) { if (yPos + increment > pageHeight - margin) { doc.addPage(); yPos = margin; } }
doc.setFontSize(18); doc.setTextColor(primaryColor);
doc.text("Savings Growth & Compound Interest Projection", 14, yPos); yPos += 8;
doc.setFontSize(10); doc.setTextColor(textColor);
doc.text(`Report Date: ${new Date().toLocaleDateString()}`, 14, yPos); yPos += 10;
checkYPdf(35);
doc.setFontSize(12); doc.setTextColor(primaryColor); doc.text("Input Parameters", 14, yPos); yPos += 6;
let inputsBody = [
['Initial Principal:', `$${inputs.initialPrincipal.toFixed(2)}`],
['Contribution Amount:', `$${inputs.contributionAmount.toFixed(2)} (per ${inputs.compoundingFrequencyText.toLowerCase()} period)`],
['Annual Interest Rate:', `${inputs.annualInterestRate.toFixed(2)}%`],
['Compounding Frequency:', inputs.compoundingFrequencyText],
['Investment Duration:', `${inputs.investmentDurationYears} years`],
['Annual Inflation Rate:', `${inputs.annualInflationRate > 0 ? inputs.annualInflationRate.toFixed(2) + '%' : 'Not Considered'}`]
];
doc.autoTable({startY: yPos, body: inputsBody, theme:'plain', styles:{fontSize:9, cellPadding:1.5}, columnStyles:{0:{fontStyle:'bold'}}});
yPos = doc.lastAutoTable.finalY + 7;
checkYPdf(30);
doc.setFontSize(12); doc.setTextColor(primaryColor); doc.text("Projection Summary", 14, yPos); yPos += 6;
let summaryBody = [
['Projected Future Value:', `$${results.futureValue.toFixed(2)}`],
['Total Principal Contributed:', `$${results.totalPrincipalContributed.toFixed(2)}`],
['Total Interest Earned:', `$${results.totalInterestEarned.toFixed(2)}`]
];
if(results.realFutureValue !== null){
summaryBody.push(['Future Value in Today\'s Dollars:', `$${results.realFutureValue.toFixed(2)}`]);
}
doc.autoTable({startY: yPos, body: summaryBody, theme:'plain', styles:{fontSize:9, cellPadding:1.5}, columnStyles:{0:{fontStyle:'bold'}}});
yPos = doc.lastAutoTable.finalY + 10;
if (results.yearlyBreakdown && results.yearlyBreakdown.length > 0) {
checkYPdf(15);
doc.setFontSize(12); doc.setTextColor(primaryColor); doc.text("Year-by-Year Growth Breakdown", 14, yPos); yPos += 6;
const head = [['Year', 'Start Balance ($)', 'Contributions ($)', 'Interest ($)', 'End Balance ($)']];
if (inputs.annualInflationRate > 0) {
head[0].push("End Bal. (Today's $)");
}
const body = results.yearlyBreakdown.map(row => {
let rowData = [row.year, row.startingBalance.toFixed(2), row.contributions.toFixed(2), row.interest.toFixed(2), row.endingBalance.toFixed(2)];
if (inputs.annualInflationRate > 0 && row.realValueEndingBalance !== null) {
rowData.push(row.realValueEndingBalance.toFixed(2));
} else if (inputs.annualInflationRate > 0) {
rowData.push('N/A');
}
return rowData;
});
doc.autoTable({
startY: yPos, head: head, body: body, theme: 'grid',
headStyles: { fillColor: tableHeaderColor, textColor: textColor, fontStyle: 'bold', fontSize: 8.5 },
styles: { fontSize: 8, cellPadding: 1.5, halign: 'right' },
columnStyles: { 0: { halign: 'center' } }
});
}
doc.save("Savings_Growth_Projection.pdf");
}
updateSGRNavButtons(); // Initial call