Financial Fraud Detection Tool

Financial Fraud Detection Tool

Enter Transaction Details

Fraud Detection Results

Results will appear here after detection.

Amount: $${amount.toFixed(2)}

Type: ${transactionType.charAt(0).toUpperCase() + transactionType.slice(1)}

Location: ${location}

Description: ${description || 'N/A'}

`; if (isFraudulent) { resultHtml += `

Status: HIGH RISK OF FRAUD

`; resultHtml += `

Reason(s):

    `; fraudReason.forEach(reason => { resultHtml += `
  • ${reason}
  • `; }); resultHtml += `
`; } else if (fraudReason.length > 0) { // Suspicious but not high risk resultHtml += `

Status: SUSPICIOUS ACTIVITY

`; resultHtml += `

Reason(s):

    `; fraudReason.forEach(reason => { resultHtml += `
  • ${reason}
  • `; }); resultHtml += `
`; } else { resultHtml += `

Status: LOW RISK / NO FRAUD DETECTED

`; recommendations.push('No immediate action required. Continue monitoring.'); } resultsOutput.innerHTML = resultHtml; // Populate recommendations recommendationList.innerHTML = ''; // Clear previous recommendations if (recommendations.length > 0) { recommendations.forEach(rec => { const li = document.createElement('li'); li.textContent = rec; recommendationList.appendChild(li); }); recommendationsOutput.classList.remove('hidden'); } else { recommendationsOutput.classList.add('hidden'); } // Show PDF download button pdfDownloadButton.classList.remove('hidden'); // Switch to results tab openTab('tab2', 'tab2-button'); }; /** * Resets the input form and clears results. */ window.resetForm = function() { document.getElementById('transaction-id').value = ''; document.getElementById('amount').value = ''; document.getElementById('transaction-type').value = 'purchase'; document.getElementById('location').value = ''; document.getElementById('description').value = ''; resultsOutput.innerHTML = '

Results will appear here after detection.

'; recommendationsOutput.classList.add('hidden'); pdfDownloadButton.classList.add('hidden'); openTab('tab1', 'tab1-button'); // Go back to the input tab }; /** * Generates and downloads a PDF of the results. */ window.downloadPdf = function() { // Ensure jsPDF library is available if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') { console.error('jsPDF library not loaded.'); resultsOutput.innerHTML = '

Error: PDF generation library not available. Please try again later.

'; return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Add title doc.setFontSize(22); doc.setTextColor(43, 108, 176); // Blue color for title doc.text("Financial Fraud Detection Report", 105, 20, null, null, "center"); // Get content from results area const resultsContent = resultsOutput.innerText; const recommendationsContent = recommendationList.innerText; // Add input details doc.setFontSize(14); doc.setTextColor(55, 65, 81); // Dark gray doc.text("Transaction Details:", 20, 40); doc.setFontSize(12); doc.text(`Transaction ID: ${document.getElementById('transaction-id').value}`, 20, 50); doc.text(`Amount: $${parseFloat(document.getElementById('amount').value).toFixed(2)}`, 20, 60); doc.text(`Type: ${document.getElementById('transaction-type').value}`, 20, 70); doc.text(`Location: ${document.getElementById('location').value}`, 20, 80); doc.text(`Description: ${document.getElementById('description').value || 'N/A'}`, 20, 90); // Add detection results doc.setFontSize(14); doc.setTextColor(55, 65, 81); doc.text("Detection Results:", 20, 110); doc.setFontSize(12); doc.setTextColor(0, 0, 0); // Black for general text // Use a different approach for multi-line text from resultsOutput let yPos = 120; resultsContent.split('\n').forEach(line => { if (line.trim() !== '') { doc.text(line.trim(), 20, yPos); yPos += 7; // Line height } }); // Add recommendations if present if (recommendationsContent) { yPos += 10; // Add some space doc.setFontSize(14); doc.setTextColor(55, 65, 81); doc.text("Recommendations:", 20, yPos); doc.setFontSize(12); doc.setTextColor(0, 0, 0); yPos += 7; recommendationsContent.split('\n').forEach(line => { if (line.trim() !== '') { doc.text(`• ${line.trim()}`, 25, yPos); // Indent for list yPos += 7; } }); } // Save the PDF doc.save('Fraud_Detection_Report.pdf'); }; });
Scroll to Top