import { useState } from 'react'; import { View, Text, FlatList, TouchableOpacity, ActivityIndicator, RefreshControl } from 'react-native'; import { useQuery } from '@tanstack/react-query'; import { router } from 'expo-router'; import { api } from '../../../services/api'; const METHOD_ICON: Record = { CASH: '๐Ÿ’ต', GCASH: '๐Ÿ“ฑ', MAYA: '๐Ÿ’™', BANK: '๐Ÿฆ' }; export default function PaymentsScreen() { const { data, isLoading, refetch, isRefetching } = useQuery({ queryKey: ['payments'], queryFn: () => api.get('/api/v1/payments?limit=50').then(r => r.data?.data ?? r.data ?? []), }); const payments: any[] = data ?? []; // Calculate today's total const today = new Date().toDateString(); const todayTotal = payments .filter((p: any) => new Date(p.paymentDate ?? p.createdAt).toDateString() === today) .reduce((sum: number, p: any) => sum + Number(p.amount), 0); return ( {/* Header */} Payments Today: โ‚ฑ{todayTotal.toLocaleString()} router.push('/(app)/payments/record')} > + Record {isLoading ? ( ) : ( item.id} refreshControl={} contentContainerStyle={{ padding: 16, paddingBottom: 32 }} ListEmptyComponent={ ๐Ÿ’ณ No payments yet router.push('/(app)/payments/record')} > Record First Payment } renderItem={({ item }) => ( {METHOD_ICON[item.paymentMethod] ?? '๐Ÿ’ณ'} {item.client?.firstName} {item.client?.lastName} {item.client?.accountNumber} {new Date(item.paymentDate ?? item.createdAt).toLocaleDateString()} ยท {item.paymentMethod} {item.referenceNumber && ( Ref: {item.referenceNumber} )} โ‚ฑ{Number(item.amount).toLocaleString()} )} /> )} ); }