Risk Analysis Report Generator

Risk Analysis Report Generator

A step-by-step tool to identify, assess, and mitigate project risks.

Mitigation Plan: ${risk.mitigation || 'N/A'}

`; }); } else { html += `

No risks have been identified. Please add risks in the 'Risk Identification' tab.

`; } reportPreviewOutput.innerHTML = html; downloadPdfBtn.classList.remove('hidden'); }; const downloadPDF = () => { const { jsPDF } = window; const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const projectName = document.getElementById('projectName').value || 'N/A'; const analystName = document.getElementById('analystName').value || 'N/A'; let reportDate = document.getElementById('reportDate').value; if (reportDate) { const date = new Date(reportDate); reportDate = new Intl.DateTimeFormat('en-US', { dateStyle: 'long' }).format(date); } else { reportDate = new Intl.DateTimeFormat('en-US', { dateStyle: 'long' }).format(new Date()); } const execSummary = document.getElementById('execSummary').value; // --- Title Page --- pdf.setFontSize(28); pdf.setFont('helvetica', 'bold'); pdf.text('Risk Analysis Report', pdf.internal.pageSize.getWidth() / 2, 100, { align: 'center' }); pdf.setFontSize(16); pdf.setFont('helvetica', 'normal'); pdf.text(`Project: ${projectName}`, pdf.internal.pageSize.getWidth() / 2, 140, { align: 'center' }); pdf.autoTable({ startY: 300, body: [ ['Prepared By:', analystName], ['Date of Report:', reportDate], ], theme: 'plain', styles: { fontSize: 12 }, }); pdf.addPage(); // --- Executive Summary --- pdf.setFontSize(18); pdf.setFont('helvetica', 'bold'); pdf.text('Executive Summary', 40, 60); pdf.setFontSize(11); pdf.setFont('helvetica', 'normal'); const summaryLines = pdf.splitTextToSize(execSummary || 'No summary provided.', pdf.internal.pageSize.getWidth() - 80); pdf.text(summaryLines, 40, 80); // --- Risk Summary Table --- const allRisks = getAllRiskData(); const tableHead = [['ID', 'Risk Title', 'Likelihood', 'Impact', 'Risk Level']]; const tableBody = allRisks.map(r => [r.id, r.title, r.likelihoodText, r.impactText, r.level]); pdf.autoTable({ head: tableHead, body: tableBody, startY: pdf.autoTable.previous.finalY + 40, didDrawCell: (data) => { if (data.section === 'body' && data.column.index === 4) { let color; switch (data.cell.raw.toLowerCase()) { case 'low': color = [220, 252, 231]; break; // green case 'medium': color = [254, 249, 195]; break; // yellow case 'high': color = [254, 226, 226]; break; // red case 'critical': color = [229, 229, 229]; break; // neutral default: color = [255, 255, 255]; } pdf.setFillColor.apply(this, color); pdf.rect(data.cell.x, data.cell.y, data.cell.width, data.cell.height, 'F'); pdf.setTextColor(30, 41, 59); pdf.text(data.cell.text, data.cell.x + data.cell.padding('left'), data.cell.y + data.cell.height / 2, { verticalAlign: 'middle' }); } }, headStyles: { fillColor: [15, 118, 110] }, // Teal margin: { top: 40 } }); // --- Detailed Breakdown --- if (allRisks.length > 0) { pdf.addPage(); pdf.setFontSize(18); pdf.setFont('helvetica', 'bold'); pdf.text('Detailed Risk Breakdown', 40, 60); let y = 80; allRisks.forEach(risk => { const blockHeight = (pdf.splitTextToSize(risk.description, 400).length + pdf.splitTextToSize(risk.mitigation, 400).length) * 12 + 60; if (y + blockHeight > pdf.internal.pageSize.getHeight() - 40) { pdf.addPage(); y = 60; } pdf.setFontSize(14); pdf.setFont('helvetica', 'bold'); pdf.text(`${risk.id}. ${risk.title}`, 40, y); y += 20; pdf.setFontSize(11); pdf.setFont('helvetica', 'bold'); pdf.text('Description:', 50, y); pdf.setFont('helvetica', 'normal'); pdf.text(pdf.splitTextToSize(risk.description || 'N/A', pdf.internal.pageSize.getWidth() - 110), 120, y); y += pdf.splitTextToSize(risk.description, 400).length * 12 + 10; pdf.setFont('helvetica', 'bold'); pdf.text('Mitigation:', 50, y); pdf.setFont('helvetica', 'normal'); pdf.text(pdf.splitTextToSize(risk.mitigation || 'N/A', pdf.internal.pageSize.getWidth() - 110), 120, y); y += pdf.splitTextToSize(risk.mitigation, 400).length * 12 + 30; }); } pdf.save(`Risk_Analysis_Report_${projectName.replace(/ /g, '_')}.pdf`); }; // --- EVENT LISTENERS --- tabButtons.forEach((button, index) => button.addEventListener('click', () => showTab(index))); prevBtn.addEventListener('click', () => { if (currentTab > 0) showTab(currentTab - 1); }); nextBtn.addEventListener('click', () => { if (currentTab < tabButtons.length - 1) showTab(currentTab + 1); }); addRiskBtn.addEventListener('click', addRisk); generateReportBtn.addEventListener('click', generateReportPreview); downloadPdfBtn.addEventListener('click', downloadPDF); // --- INITIALIZATION --- document.getElementById('reportDate').valueAsDate = new Date(); addRisk(); // Start with one risk block updateTabs(); });
Scroll to Top