import { createResource, Show, For } from 'solid-js'; const API = '/api/gateway'; type LedgerEntry = { id: string; entry_type?: string; type?: string; order_id?: string; invoice_id?: string; user_id?: string; amount?: number; note?: string; created_at?: string; }; async function loadLedger(): Promise { try { const res = await fetch(`${API}/api/admin/ledger`); if (!res.ok) throw new Error('Failed to load'); const data = await res.json(); return Array.isArray(data) ? data : (data.entries || data.ledger || []); } catch { return []; } } function typeBadgeStyle(entryType: string): string { switch ((entryType || '').toUpperCase()) { case 'TRACECOIN_PURCHASE': return 'background:#dbeafe;color:#1d4ed8;border-color:#bfdbfe'; case 'PAYMENT': return 'background:#dcfce7;color:#166534;border-color:#bbf7d0'; case 'DISCOUNT': return 'background:#fff7ed;color:#c2410c;border-color:#fed7aa'; case 'COUPON': return 'background:#f3e8ff;color:#7e22ce;border-color:#e9d5ff'; case 'INVOICE': default: return 'background:#f1f5f9;color:#475569;border-color:#e2e8f0'; } } function formatAmount(entry: LedgerEntry): string { const t = (entry.entry_type || entry.type || '').toUpperCase(); if (t === 'TRACECOIN_PURCHASE') { return entry.amount != null ? `${entry.amount} TC` : '—'; } if (entry.amount == null) return '—'; return `₹${(entry.amount / 100).toFixed(2)}`; } export default function LedgerPage() { const [entries] = createResource(loadLedger); return (

Ledger Management

Platform financial ledger

0}> {(item) => { const entryType = item.entry_type || item.type || '—'; return ( ); }}
Type Order ID Invoice ID User ID Amount Note Date
Loading...
Failed to load. Is the backend running?
No ledger entries found.
{entryType} {item.order_id || '—'} {item.invoice_id || '—'} {item.user_id || '—'} {formatAmount(item)} {item.note || '—'} {item.created_at ? new Date(item.created_at).toLocaleString() : '—'}
); }