`;
redFlagsOutputDiv.innerHTML += flagHtml;
});
}
/**
* Resets all input fields to their default values and clears output sections.
*/
function resetForm() {
// Reset Input fields to example values (or empty if preferred)
document.getElementById('currentRevenue').value = "12000000";
document.getElementById('priorRevenue').value = "10000000";
document.getElementById('currentCogs').value = "5000000";
document.getElementById('priorCogs').value = "4000000";
document.getElementById('currentOperatingExpenses').value = "4000000";
document.getElementById('priorOperatingExpenses').value = "3500000";
document.getElementById('currentRnd').value = "500000";
document.getElementById('priorRnd').value = "450000";
document.getElementById('currentSgna').value = "1500000";
document.getElementById('priorSgna').value = "1300000";
document.getElementById('currentNetIncome').value = "1000000";
document.getElementById('priorNetIncome').value = "800000";
document.getElementById('currentAccountsReceivable').value = "600000";
document.getElementById('priorAccountsReceivable').value = "400000";
document.getElementById('currentInventory').value = "800000";
document.getElementById('priorInventory').value = "650000";
document.getElementById('currentPpe').value = "6000000";
document.getElementById('priorPpe').value = "5000000";
document.getElementById('currentTotalDebt').value = "3000000";
document.getElementById('priorTotalDebt').value = "2500000";
document.getElementById('currentCfOps').value = "900000";
document.getElementById('priorCfOps').value = "700000";
document.getElementById('currentCapex').value = "1000000";
document.getElementById('priorCapex').value = "800000";
// Clear stored results
window.shenanigansAnalysisResults = null;
// Clear output div
redFlagsOutputDiv.innerHTML = '
Enter financial data and click "Detect Shenanigans" to see results.
'; // Reset to the first tab openTab('inputs'); hideMessage(); } /** * Downloads the earnings manipulation analysis as a PDF. */ function downloadPDF() { if (!window.shenanigansAnalysisResults) { showMessage('Please perform the analysis first.', 'info'); return; } const { jsPDF } = window.jspdf; const pdf = new jsPDF('p', 'mm', 'a4'); // 'p' for portrait, 'mm', 'a4' size const BLACK_COLOR = [31, 41, 55]; // Tailwind gray-900 equivalent const BLUE_HEADER_COLOR = [29, 78, 216]; // Tailwind blue-700 equivalent const RED_FLAG_COLOR = [239, 68, 68]; // Red-500 const YELLOW_FLAG_COLOR = [245, 158, 11]; // Yellow-500 const GREEN_FLAG_COLOR = [16, 185, 129]; // Green-500 let y = 15; // Y-coordinate for placing content // Title pdf.setFontSize(22); pdf.setFont('helvetica', 'bold'); pdf.setTextColor(BLACK_COLOR[0], BLACK_COLOR[1], BLACK_COLOR[2]); pdf.text('Earnings Manipulation & Financial Shenanigans Report', 105, y, { align: 'center' }); y += 15; // --- 1. Input Data Section --- pdf.setFontSize(16); pdf.setFont('helvetica', 'bold'); pdf.text('1. Financial Data Inputs', 15, y); y += 8; const inputs = window.shenanigansAnalysisResults.inputs; const inputData = [ ['Current Year Revenue', formatCurrency(inputs.currentRevenue)], ['Prior Year Revenue', formatCurrency(inputs.priorRevenue)], ['Current Year COGS', formatCurrency(inputs.currentCogs)], ['Prior Year COGS', formatCurrency(inputs.priorCogs)], ['Current Year Operating Expenses', formatCurrency(inputs.currentOperatingExpenses)], ['Prior Year Operating Expenses', formatCurrency(inputs.priorOperatingExpenses)], ['Current Year R&D Expenses', formatCurrency(inputs.currentRnd)], ['Prior Year R&D Expenses', formatCurrency(inputs.priorRnd)], ['Current Year SG&A Expenses', formatCurrency(inputs.currentSgna)], ['Prior Year SG&A Expenses', formatCurrency(inputs.priorSgna)], ['Current Year Net Income', formatCurrency(inputs.currentNetIncome)], ['Prior Year Net Income', formatCurrency(inputs.priorNetIncome)], ['Current Year Accounts Receivable', formatCurrency(inputs.currentAccountsReceivable)], ['Prior Year Accounts Receivable', formatCurrency(inputs.priorAccountsReceivable)], ['Current Year Inventory', formatCurrency(inputs.currentInventory)], ['Prior Year Inventory', formatCurrency(inputs.priorInventory)], ['Current Year PPE (Net)', formatCurrency(inputs.currentPpe)], ['Prior Year PPE (Net)', formatCurrency(inputs.priorPpe)], ['Current Year Total Debt', formatCurrency(inputs.currentTotalDebt)], ['Prior Year Total Debt', formatCurrency(inputs.priorTotalDebt)], ['Current Year Cash Flow from Operations', formatCurrency(inputs.currentCfOps)], ['Prior Year Cash Flow from Operations', formatCurrency(inputs.priorCfOps)], ['Current Year Capital Expenditures (Capex)', formatCurrency(inputs.currentCapex)], ['Prior Year Capital Expenditures (Capex)', formatCurrency(inputs.priorCapex)] ]; pdf.autoTable({ startY: y, head: [['Parameter', 'Value']], body: inputData, theme: 'grid', styles: { fontSize: 8, cellPadding: 2, overflow: 'linebreak', lineColor: 200, lineWidth: 0.1 }, headStyles: { fillColor: BLUE_HEADER_COLOR, textColor: 255, fontStyle: 'bold' }, margin: { left: 15, right: 15 }, columnStyles: { 0: { cellWidth: 80 }, 1: { cellWidth: 'auto' } } }); y = pdf.autoTable.previous.finalY + 15; // --- 2. Detected Red Flags Section --- pdf.setFontSize(16); pdf.setFont('helvetica', 'bold'); pdf.text('2. Detected Red Flags', 15, y); y += 8; const redFlags = window.shenanigansAnalysisResults.redFlags; if (redFlags.length === 0) { if (y + 10 > pdf.internal.pageSize.height - 15) { pdf.addPage(); y = 15; } pdf.setFontSize(10); pdf.setTextColor(GREEN_FLAG_COLOR[0], GREEN_FLAG_COLOR[1], GREEN_FLAG_COLOR[2]); pdf.text('No significant red flags detected based on the provided data and simplified criteria.', 15, y); y += 10; } else { redFlags.forEach(flag => { // Check if content fits on current page, if not, add new page if (y + 25 > pdf.internal.pageSize.height - 15) { // Estimate 25mm for a flag block pdf.addPage(); y = 15; // Reset y for new page pdf.setFontSize(16); pdf.setFont('helvetica', 'bold'); pdf.text('2. Detected Red Flags (Continued)', 15, y); y += 8; } let textColor = BLACK_COLOR; if (flag.class === 'red-flag') textColor = RED_FLAG_COLOR; else if (flag.class === 'yellow-flag') textColor = YELLOW_FLAG_COLOR; else if (flag.class === 'green-flag') textColor = GREEN_FLAG_COLOR; pdf.setFontSize(12); pdf.setFont('helvetica', 'bold'); pdf.setTextColor(textColor[0], textColor[1], textColor[2]); pdf.text(`${flag.type}: ${flag.flag}`, 15, y); y += 7; pdf.setFontSize(10); pdf.setFont('helvetica', 'normal'); pdf.setTextColor(BLACK_COLOR[0], BLACK_COLOR[1], BLACK_COLOR[2]); const splitExplanation = pdf.splitTextToSize(flag.explanation, pdf.internal.pageSize.width - 30); pdf.text(splitExplanation, 15, y); y += (splitExplanation.length * 5) + 5; // Adjust Y based on lines of explanation + padding }); } pdf.save('Earnings_Shenanigans_Report.pdf'); } /** * Initializes DOM element references once the document is fully loaded. */ document.addEventListener('DOMContentLoaded', () => { // Input Elements currentRevenueInput = document.getElementById('currentRevenue'); priorRevenueInput = document.getElementById('priorRevenue'); currentCogsInput = document.getElementById('currentCogs'); priorCogsInput = document.getElementById('priorCogs'); currentOperatingExpensesInput = document.getElementById('currentOperatingExpenses'); priorOperatingExpensesInput = document.getElementById('priorOperatingExpenses'); currentRndInput = document.getElementById('currentRnd'); priorRndInput = document.getElementById('priorRnd'); currentSgnaInput = document.getElementById('currentSgna'); priorSgnaInput = document.getElementById('priorSgna'); currentNetIncomeInput = document.getElementById('currentNetIncome'); priorNetIncomeInput = document.getElementById('priorNetIncome'); currentAccountsReceivableInput = document.getElementById('currentAccountsReceivable'); priorAccountsReceivableInput = document.getElementById('priorAccountsReceivable'); currentInventoryInput = document.getElementById('currentInventory'); priorInventoryInput = document.getElementById('priorInventory'); currentPpeInput = document.getElementById('currentPpe'); priorPpeInput = document.getElementById('priorPpe'); currentTotalDebtInput = document.getElementById('currentTotalDebt'); priorTotalDebtInput = document.getElementById('priorTotalDebt'); currentCfOpsInput = document.getElementById('currentCfOps'); priorCfOpsInput = document.getElementById('priorCfOps'); currentCapexInput = document.getElementById('currentCapex'); priorCapexInput = document.getElementById('priorCapex'); // Output Elements redFlagsOutputDiv = document.getElementById('redFlagsOutput'); messageBox = document.getElementById('messageBox'); // Initialize navigation button states updateNavigationButtons(); });