`;
container.appendChild(div);
});
}
window.amlUpdateDashboard = function() {
// 1. Metrics Calculation
const totalRules = amlRules.length;
const totalDays = amlRules.reduce((sum, current) => sum + current.days, 0);
const avgDays = totalRules > 0 ? Math.round(totalDays / totalRules) : 0;
// Score based on minimum scenario coverage (Max 5 rules = 100%)
const completionPct = Math.min(100, Math.round((totalRules / TOTAL_SCENARIOS) * 100));
// 2. Update Dashboard Metrics
document.getElementById('aml-out-total-rules').innerText = totalRules;
document.getElementById('aml-out-avg-days').innerText = avgDays;
document.getElementById('aml-score-percent').innerText = completionPct + "%";
// 3. Update Chart
if (amlChart) {
amlChart.data.datasets[0].data = [completionPct, 100 - completionPct];
const color = completionPct === 100 ? '#2ecc71' : (completionPct >= 60 ? '#ff9800' : '#007bff');
amlChart.data.datasets[0].backgroundColor = [color, '#e9ecef'];
amlChart.update();
}
};
window.amlResetData = function(silent = false) {
if(silent || confirm("Clear all rules and metadata?")) {
amlRules = [
{ id: 1, title: "Structuring Detection (Rule 1A)", type: "Structuring", threshold: 8000, days: 10, count: 5, status: "Active" },
{ id: 2, title: "Rapid Fund Movement", type: "Wire Activity", threshold: 50000, days: 3, count: 1, status: "Pending" }
];
currentRuleId = 3;
document.getElementById('aml-cfg-system').value = 'Guardian Monitor v2.1';
document.getElementById('aml-cfg-jurisdiction').value = 'USA (BSA/FINCEN)';
amlRenderRules();
amlUpdateDashboard();
if (!silent) alert("Ruleset reset to template.");
}
};
// --- Chart Logic ---
window.amlInitChart = function() {
const ctx = document.getElementById('aml-chart').getContext('2d');
amlChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['Scenarios Defined', 'Gap'],
datasets: [{
data: [0, 100],
backgroundColor: ['#007bff', '#e9ecef'],
borderWidth: 0,
cutout: '75%'
}]
},
options: {
circumference: 180,
rotation: -90,
cutout: '75%',
responsive: true,
maintainAspectRatio: false,
plugins: { legend: { display: false }, tooltip: { enabled: false } },
aspectRatio: 1.5
}
});
};
// --- PDF Export ---
window.amlDownloadPDF = function() {
const element = document.getElementById('aml-export-area');
const system = document.getElementById('aml-cfg-system').value;
const jurisdiction = document.getElementById('aml-cfg-jurisdiction').value;
// Create a temporary wrapper for the PDF with header and content
const tempDiv = document.createElement('div');
tempDiv.style.padding = '20px';
tempDiv.style.backgroundColor = '#ffffff';
tempDiv.style.color = '#000';
// Header
tempDiv.innerHTML = `
Rule Documentation (Total: ${amlRules.length})
`;
// Add all rule cards (re-formatting for print visibility)
amlRules.forEach(rule => {
const logicText = `IF Sum(Transactions) > $${rule.threshold.toLocaleString()} AND Count(Transactions) >= ${rule.count} WITHIN ${rule.days} days.`;
tempDiv.innerHTML += `
${rule.title} (ID: R${rule.id})
TYPE: ${rule.type} | STATUS: ${rule.status}
LOGIC: ${logicText}
`;
});
const opt = {
margin: 0.5,
filename: 'AML_Rule_Documentation.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
};
html2pdf().set(opt).from(tempDiv).save();
};
})();