Payment Reconciliation Tool

Payment Reconciliation Tool

Compare internal records with bank statements to find discrepancies.

${bankOnly.length}

${renderResultTables(appData.results)}
`; renderReconciliationChart(appData.results); document.getElementById('download-pdf-btn').addEventListener('click', generatePdf); }; const renderReconciliationChart = ({ matched, discrepancies, internalOnly, bankOnly }) => { const ctx = document.getElementById('reconciliation-chart').getContext('2d'); if (charts.reconciliation) charts.reconciliation.destroy(); charts.reconciliation = new Chart(ctx, { type: 'doughnut', data: { labels: ['Matched', 'Discrepancies', 'Internal Only', 'Bank Only'], datasets: [{ data: [matched.length, discrepancies.length, internalOnly.length, bankOnly.length], backgroundColor: ['#d1fae5', '#fef3c7', '#e0e7ff', '#fee2e2'], borderColor: ['#10b981', '#f59e0b', '#4f46e5', '#ef4444'], borderWidth: 1 }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom' } } } }); }; const renderResultTables = ({ matched, discrepancies, internalOnly, bankOnly }) => { const createTable = (title, headers, rows, tagClass, tagText) => `

${title} ${rows.length} ${tagText}

${headers.map(h => ``).join('')}${rows.join('')}
${h}
`; const matchedRows = matched.map(r => `${r['Transaction ID']}${r.Date}${formatCurrency(r.Amount)}`); const discrepancyRows = discrepancies.map(r => `${r['Transaction ID']}${r.Date}${formatCurrency(r.Amount)}${formatCurrency(r.bankAmount)}${formatCurrency(r.amountDiff)}`); const internalOnlyRows = internalOnly.map(r => `${r['Transaction ID']}${r.Date}${formatCurrency(r.Amount)}`); const bankOnlyRows = bankOnly.map(r => `${r['Transaction ID']}${r.Date}${formatCurrency(r.Amount)}`); return ` ${createTable('Matched Transactions', ['ID', 'Date', 'Amount'], matchedRows, 'status-matched', 'Matched')} ${createTable('Discrepancies', ['ID', 'Date', 'Internal Amt', 'Bank Amt', 'Difference'], discrepancyRows, 'status-discrepancy', 'Discrepancies')} ${createTable('Internal Records Only', ['ID', 'Date', 'Amount'], internalOnlyRows, 'status-internal-only', 'Unmatched')} ${createTable('Bank Statement Items Only', ['ID', 'Date', 'Amount'], bankOnlyRows, 'status-bank-only', 'Unmatched')} `; }; const renderDataInput = () => { const inputContent = document.getElementById('content-data-input'); if (!inputContent) return; inputContent.innerHTML = `

Input Transaction Data

Paste your data in CSV format below. Ensure the header contains 'Transaction ID', 'Date', and 'Amount'.

`; document.getElementById('reconcile-btn').addEventListener('click', () => { appData.internalData = document.getElementById('internal-data').value; appData.bankData = document.getElementById('bank-data').value; appData.results = null; renderDashboard(); switchTab(0); }); }; const generatePdf = () => { loadingOverlay.style.display = 'flex'; const { jsPDF } = window.jspdf; document.getElementById('pdf-generated-date').textContent = new Date().toLocaleDateString('en-US'); const pdfHeader = document.getElementById('pdf-header'); pdfHeader.classList.remove('hidden'); const fullContent = document.getElementById('pdf-content-area'); html2canvas(fullContent, { scale: 2, useCORS: true, logging: false, windowWidth: 1200 }) .then(canvas => { pdfHeader.classList.add('hidden'); const imgData = canvas.toDataURL('image/jpeg', 0.9); const pdf = new jsPDF({ orientation: 'portrait', unit: 'px', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgProps = pdf.getImageProperties(imgData); const imgHeight = (imgProps.height * pdfWidth) / imgProps.width; let heightLeft = imgHeight; let position = 0; pdf.addImage(imgData, 'JPEG', 0, position, pdfWidth, imgHeight); heightLeft -= pdf.internal.pageSize.getHeight(); while (heightLeft > 0) { position = heightLeft - imgHeight; pdf.addPage(); pdf.addImage(imgData, 'JPEG', 0, position, pdfWidth, imgHeight); heightLeft -= pdf.internal.pageSize.getHeight(); } pdf.save('Payment-Reconciliation-Report.pdf'); loadingOverlay.style.display = 'none'; }).catch(err => { console.error("PDF generation failed:", err); pdfHeader.classList.add('hidden'); loadingOverlay.style.display = 'none'; alert('An error occurred generating the PDF.'); }); }; // --- TAB NAVIGATION & INITIALIZATION --- const switchTab = (tabIndex) => { activeTabIndex = tabIndex; document.querySelectorAll('.tab-btn').forEach((btn, i) => btn.classList.toggle('active', i === tabIndex)); document.querySelectorAll('.tab-content').forEach((content, i) => content.classList.toggle('hidden', i !== tabIndex)); updateNavButtons(); }; const updateNavButtons = () => { prevTabBtn.disabled = activeTabIndex === 0; nextTabBtn.disabled = activeTabIndex === tabIdentifiers.length - 1; }; const initializeUI = () => { const tabs = [ { name: 'Reconciliation Dashboard', id: 'reconciliation-dashboard' }, { name: 'Data Input', id: 'data-input' } ]; tabIdentifiers = tabs.map(t => t.id); tabsContainer.innerHTML = tabs.map(tab => ``).join(''); mainContent.innerHTML = tabs.map(tab => `
`).join(''); tabs.forEach((tab, index) => { document.getElementById(`tab-${tab.id}`).addEventListener('click', () => switchTab(index)); }); renderDashboard(); renderDataInput(); switchTab(0); lucide.createIcons(); }; initializeUI(); prevTabBtn.addEventListener('click', () => { if (activeTabIndex > 0) switchTab(activeTabIndex - 1); }); nextTabBtn.addEventListener('click', () => { if (activeTabIndex < tabIdentifiers.length - 1) switchTab(activeTabIndex + 1); }); });
Scroll to Top