/** * Reports Page Logic - Aadhaar Pro */ document.addEventListener('DOMContentLoaded', () => { if (typeof flatpickr !== 'undefined') { flatpickr(".date-picker", { dateFormat: "Y-m-d", allowInput: true }); } loadReports(); }); async function loadReports(filters = {}) { const listEl = document.getElementById('reports-list'); if (!listEl) return; try { let url = '/api/wallet/ledger'; if (filters.from || filters.to) { const params = new URLSearchParams(filters); url += `?${params.toString()}`; } const res = await fetch(url); const data = await res.json(); if (data && data.length > 0) { const items = data.map(item => { let displayId = item.id ? item.id.substring(0, 8) + '...' : 'N/A'; if (item.description && item.description.includes('Aadhaar Advance: ')) { const parts = item.description.split('Aadhaar Advance: '); if (parts.length > 1) displayId = parts[1]; } const statusClass = item.type === 'credit' ? 'status-approved' : 'status-rejected'; const statusIcon = item.type === 'credit' ? 'fa-arrow-down' : 'fa-arrow-up'; const statusText = item.type === 'credit' ? 'CREDIT' : 'DEBIT'; const amountPrefix = item.type === 'credit' ? '+' : '-'; const amountClass = item.type === 'credit' ? 'amount-plus' : 'amount-minus'; return `
${amountPrefix} ₹${item.amount.toFixed(2)}
${item.description} ${item.date}
Balance: ₹${item.balance_after.toFixed(2)} ${displayId}
${statusText}
`; }).join(''); listEl.innerHTML = items; } else { listEl.innerHTML = `

No reports found

No transactions for the selected period

`; } } catch (err) { console.error('Error loading reports:', err); listEl.innerHTML = `

Failed to load

Could not fetch report data

`; } } function applyFilter() { const from = document.getElementById('from-date').value; const to = document.getElementById('to-date').value; loadReports({ from, to }); } window.applyFilter = applyFilter;