'use client'; import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { Card, CardContent } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Skeleton } from '@/components/ui/skeleton'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table'; import { Search } from 'lucide-react'; import { api } from '@/lib/api'; import { format } from 'date-fns'; interface Payment { id: string; amount: number; channel: string; paymentDate: string; notes?: string; client?: { firstName: string; lastName: string; accountNumber: string }; invoice?: { invoiceNumber: string }; recordedBy?: { firstName: string; lastName: string }; } const CHANNEL_COLORS: Record = { CASH: 'bg-emerald-100 text-emerald-700', GCASH: 'bg-blue-100 text-blue-700', MAYA: 'bg-green-100 text-green-700', BANK_TRANSFER: 'bg-purple-100 text-purple-700', CHECK: 'bg-orange-100 text-orange-700', }; export default function PaymentsPage() { const [page, setPage] = useState(1); const limit = 20; const { data, isLoading } = useQuery({ queryKey: ['payments', page], queryFn: async () => { const res = await api.get(`/api/v1/payments?page=${page}&limit=${limit}`); return res.data; }, }); const payments: Payment[] = Array.isArray(data) ? data : (data?.data ?? data?.items ?? []); const total = (data as any)?.meta?.total ?? (data as any)?.total ?? payments.length; const totalAmount = payments.reduce((sum, p) => sum + Number(p.amount), 0); return (

Payments

Payment collection records

{payments.length > 0 && (

Total (this page)

₱{totalAmount.toLocaleString()}

)}
Date Client Invoice Channel Amount Recorded By Notes {isLoading ? ( Array.from({ length: 8 }).map((_, i) => ( {Array.from({ length: 7 }).map((_, j) => ( ))} )) ) : payments.length === 0 ? ( No payments yet ) : ( payments.map((p) => ( {format(new Date(p.paymentDate), 'MMM d, yyyy')} {p.client ? `${p.client.firstName} ${p.client.lastName}` : '—'} {p.invoice?.invoiceNumber ?? '—'} {p.channel} ₱{Number(p.amount).toLocaleString()} {p.recordedBy ? `${p.recordedBy.firstName} ${p.recordedBy.lastName}` : '—'} {p.notes ?? '—'} )) )}
{total > limit && (
Page {page} of {Math.ceil(total / limit)}
)}
); }