`;
}
// --- Event Handling ---
window.amlAddTransaction = function() {
const newTxn = {
transaction_id: `TXN${Date.now() % 100000}`,
timestamp: new Date(),
customer_name: document.getElementById('add-cust-name').value,
customer_id: document.getElementById('add-cust-id').value,
amount_usd: parseFloat(document.getElementById('add-amount').value),
source_country: document.getElementById('add-source-ctry').value,
destination_country: document.getElementById('add-dest-ctry').value,
kyc_status: document.getElementById('add-kyc').value,
aml_status: 'Pending Review'
};
if(!newTxn.customer_name || !newTxn.amount_usd) { alert('Customer Name and Amount are required.'); return; }
allTransactions.unshift(newTxn);
renderAllTransactionsTable();
runAnalysisAndRender();
// Clear form
document.getElementById('add-cust-name').value = '';
document.getElementById('add-cust-id').value = '';
document.getElementById('add-amount').value = '';
document.getElementById('add-source-ctry').value = '';
document.getElementById('add-dest-ctry').value = '';
}
function handleAlertAction(e) {
if (!e.target.matches('.aml-action-btn')) return;
const action = e.target.dataset.action;
const id = e.target.dataset.id;
if (action === 'delete') {
const index = allTransactions.findIndex(t => t.transaction_id === id);
if (index > -1) allTransactions.splice(index, 1);
renderAllTransactionsTable();
} else {
const alert = highRiskAlerts.find(a => a.transaction_id === id);
if (!alert) return;
const newStatus = { investigate: "Under Investigation", clear: "Cleared", report: "Reported to Authorities" }[action];
if (newStatus) alert.aml_status = newStatus;
}
runAnalysisAndRender();
}
// --- Listeners & Initial Load ---
elements.filterStatus.addEventListener('change', renderAlertsTable);
document.getElementById('aml-alerts-tbody').addEventListener('click', handleAlertAction);
document.getElementById('all-transactions-tbody').addEventListener('click', handleAlertAction);
function initialize() {
allTransactions = [
{transaction_id: 'TXN1001', customer_name: 'John Doe', customer_id: 101, amount_usd: 15000, source_country: 'USA', destination_country: 'CYM', kyc_status: 'Verified', aml_status: 'Pending Review'},
{transaction_id: 'TXN1002', customer_name: 'Shell Corp Ltd.', customer_id: 104, amount_usd: 8500, source_country: 'USA', destination_country: 'SGP', kyc_status: 'Expired', aml_status: 'Pending Review'},
{transaction_id: 'TXN1003', customer_name: 'Global Trade Co.', customer_id: 103, amount_usd: 50000, source_country: 'SYR', destination_country: 'CHE', kyc_status: 'Verified', aml_status: 'Pending Review'}
];
renderAllTransactionsTable();
runAnalysisAndRender();
}
// --- Global Functions ---
window.amlShowTab = id => {
document.querySelectorAll('.aml-main-tab-content').forEach(c => c.classList.remove('active'));
document.querySelectorAll('.aml-main-tab-button').forEach(b => b.classList.remove('active'));
document.getElementById(`aml-tab-${id}`)?.classList.add('active');
document.querySelector(`.aml-main-tab-button[onclick="amlShowTab('${id}')"]`)?.classList.add('active');
};
window.amlDownloadPDF = () => {
html2canvas(document.getElementById('monitoring-dashboard-output'), { scale: 2 }).then(canvas => {
const pdf = new jspdf.jsPDF({ orientation: 'landscape', unit: 'pt', format: 'a4' });
pdf.addImage(canvas.toDataURL('image/png'), 'PNG', 40, 40, pdf.internal.pageSize.getWidth() - 80, 0);
pdf.save('AML_Monitoring_Report.pdf');
});
};
initialize();
});
