import { prisma } from '@/lib/prisma'; import { isAdminAuthenticated } from '@/lib/adminAuth'; import AdminNav from '@/components/AdminNav'; import Link from 'next/link'; import Price from '@/components/Price'; import { getReconciliationSummary } from '@/lib/bankReconciliation'; import ReconciliationClient from './client'; export default async function ReconciliationPage({ searchParams, }: { searchParams: Promise<{ id?: string }>; }) { const isAdmin = await isAdminAuthenticated(); if (!isAdmin) { return
Unauthorized
; } const { id: statementId } = await searchParams; if (!statementId) { // Show list of statements const statements = await prisma.bankStatement.findMany({ orderBy: { uploadedAt: 'desc' }, include: { lines: true, reconciliations: true, }, }); return (

Bank Reconciliation

⬆ Upload Statement

Upload your bank statements to match against system transactions and verify account accuracy.

{statements.length === 0 ? (

No bank statements uploaded yet.

Upload your first statement →
) : (
{statements.map((stmt) => { const matched = stmt.reconciliations.length; const total = stmt.lines.length; const reconciled = stmt.status === 'RECONCILED'; return (

{stmt.filename}

{stmt.status}

Period

{stmt.startDate.toLocaleDateString('en-GB')} to {stmt.endDate.toLocaleDateString('en-GB')}

Transactions

{total}

Matched

{matched}/{total}

Total

{stmt.reconciliedAt && (

Reconciled: {stmt.reconciliedAt.toLocaleDateString('en-GB')}

)} ); })}
)}

💡 Tip: Each uploaded statement is automatically scanned to match transactions. Review unmatched items and correct any discrepancies before archiving.

); } // Show statement detail const statement = await prisma.bankStatement.findUnique({ where: { id: statementId }, include: { lines: { orderBy: { date: 'desc' } }, reconciliations: true, }, }); if (!statement) { return
Statement not found
; } const summary = await getReconciliationSummary(statementId); return (
← Back to statements

{statement.filename}

{statement.status}
{/* Summary Stats */}

Period

{statement.startDate.toLocaleDateString('en-GB')} to {statement.endDate.toLocaleDateString('en-GB')}

Bank Total

Matched

{summary?.matched || 0}/{statement.lines.length}

Unmatched

{summary?.unmatched || 0}

Discrepancies

{summary?.discrepancies || 0}

); }