II. Projected Free Cash Flows (FCFF) & Present Values
III. Terminal Value Calculation
Last Projected FCFF (Year ${inputs.numProjectionYears}): ${dcf_formatCurrency(results.fcff_n)}
FCFF for TV Calculation (Year ${inputs.numProjectionYears + 1}): ${dcf_formatCurrency(results.fcff_n_plus_1)}
Terminal Value (at end of Year ${inputs.numProjectionYears}): ${dcf_formatCurrency(results.terminalValue_at_year_n)}
Present Value of Terminal Value: ${dcf_formatCurrency(results.pvTerminalValue)}
IV. Valuation Summary
Enterprise Value (EV): ${dcf_formatCurrency(results.enterpriseValue)}
Equity Value: ${dcf_formatCurrency(results.equityValue)}
Intrinsic Value per Share: ${dcf_formatCurrency(results.intrinsicValuePerShare)}
Important Notes: ${interpretationNote_pdf}
`;
document.body.appendChild(pdfContentEl);
html2canvas(pdfContentEl, { scale: 2, useCORS: true, logging:true, windowWidth: pdfContentEl.scrollWidth, windowHeight: pdfContentEl.scrollHeight }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
let numPages = Math.ceil(canvas.height / ( (pdfHeight - 40) * (canvas.width / (pdfWidth - 40)) ) );
let pageCanvasHeight = (pdfHeight - 40) * (canvas.width / (pdfWidth - 40));
for (let i = 0; i < numPages; i++) {
if (i > 0) pdf.addPage();
let sourceY = i * pageCanvasHeight;
let sourceHeight = Math.min(pageCanvasHeight, canvas.height - sourceY);
const tempCanvas = document.createElement('canvas');
tempCanvas.width = canvas.width;
tempCanvas.height = sourceHeight;
const ctx = tempCanvas.getContext('2d');
ctx.drawImage(canvas, 0, sourceY, canvas.width, sourceHeight, 0, 0, canvas.width, sourceHeight);
const pageImgData = tempCanvas.toDataURL('image/png');
const pageImgHeight = (sourceHeight * (pdfWidth - 40)) / canvas.width;
pdf.addImage(pageImgData, 'PNG', 20, 20, pdfWidth - 40, pageImgHeight, undefined, 'FAST');
}
pdf.save(`${(inputs.companyName || "DCF_Analysis").replace(/[^a-z0-9]/gi, '_')}.pdf`);
if(document.body.contains(pdfContentEl)) document.body.removeChild(pdfContentEl);
}).catch(err => {
console.error("DCF PDF Error:", err); alert("Error generating DCF PDF. See console.");
if(document.body.contains(pdfContentEl)) document.body.removeChild(pdfContentEl);
});
}
document.addEventListener('DOMContentLoaded', function() {
dcf_generateFcffInputs(); // Initialize with default number of FCFF inputs
dcf_openTab({}, 'dcf_tab_fcff');
// Set some default values for quicker testing
const waccEl = document.getElementById('dcf_wacc');
if (waccEl && !waccEl.value) waccEl.value = '9.0';
const pgrEl = document.getElementById('dcf_perpetualGrowthRate');
if (pgrEl && !pgrEl.value) pgrEl.value = '2.5';
const netDebtEl = document.getElementById('dcf_netDebt');
if (netDebtEl && !netDebtEl.value) netDebtEl.value = '100000000'; // $100M
const sharesEl = document.getElementById('dcf_sharesOutstanding');
if (sharesEl && !sharesEl.value) sharesEl.value = '50000000'; // 50M shares
// Default FCFFs for 5 years
const defaultFcffs = [10000000, 11000000, 12100000, 13310000, 14641000]; // Example growth
for(let i=1; i<=5; i++) {
const fcffEl = document.getElementById(`dcf_fcff_year_${i}`);
if(fcffEl && !fcffEl.value) fcffEl.value = defaultFcffs[i-1] || '';
}
if (!document.getElementById('dcf_numProjectionYears')) {
console.error("Critical input 'dcf_numProjectionYears' not found.");
}
});
