import { useState } from 'react' import { createFileRoute } from '@tanstack/react-router' import { useQuery } from '@tanstack/react-query' import { dailyReportOptions } from '@/api/pos' import { api } from '@/lib/api-client' import { queryOptions } from '@tanstack/react-query' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Badge } from '@/components/ui/badge' import { Separator } from '@/components/ui/separator' import { Skeleton } from '@/components/ui/skeleton' interface Location { id: string name: string } function locationsOptions() { return queryOptions({ queryKey: ['locations'], queryFn: () => api.get<{ data: Location[] }>('/v1/locations'), }) } export const Route = createFileRoute('/_authenticated/reports/daily')({ component: DailyReportPage, }) const PAYMENT_LABELS: Record = { cash: 'Cash', card_present: 'Card (Present)', card_keyed: 'Card (Keyed)', check: 'Check', account_charge: 'Account', } function DailyReportPage() { const today = new Date().toISOString().slice(0, 10) const [date, setDate] = useState(today) const [locationId, setLocationId] = useState(null) const { data: locationsData } = useQuery(locationsOptions()) const locations = locationsData?.data ?? [] // Auto-select first location if (!locationId && locations.length > 0) { setLocationId(locations[0].id) } const { data: report, isLoading } = useQuery(dailyReportOptions(locationId, date)) return (

Daily Report

setDate(e.target.value)} className="w-44" />
{isLoading ? (
) : !report ? (

Select a location and date to view the report.

) : (
{/* Sessions */} Drawer Sessions ({report.sessions.length}) {report.sessions.length === 0 ? (

No drawer sessions on this date.

) : (
{report.sessions.map((s: any) => (
{s.register?.name ?? 'Unassigned'} {new Date(s.openedAt).toLocaleTimeString()} — {s.closedAt ? new Date(s.closedAt).toLocaleTimeString() : 'Open'} {s.openedBy && ({s.openedBy.firstName})}
${s.grossSales.toFixed(2)} {s.overShort !== null && ( {s.overShort === 0 ? 'Balanced' : `${s.overShort > 0 ? '+' : ''}$${s.overShort.toFixed(2)}`} )} {s.status === 'open' && Open}
))}
)}
{/* Sales Summary */} Sales
Transactions{report.sales.transactionCount}
Gross Sales${report.sales.grossSales.toFixed(2)}
{report.sales.refundTotal > 0 &&
Refunds-${report.sales.refundTotal.toFixed(2)}
}
Net Sales${report.sales.netSales.toFixed(2)}
{report.sales.voidCount > 0 &&
Voided{report.sales.voidCount}
}
{/* Payment Breakdown */} Payments {Object.entries(report.payments as Record).map(([method, data]) => (
{PAYMENT_LABELS[method] ?? method} ({data.count}) ${data.total.toFixed(2)}
))} {Object.keys(report.payments).length === 0 &&

No payments

}
{/* Discounts */} {report.discounts.count > 0 && ( Discounts
Total ({report.discounts.count} transactions)-${report.discounts.total.toFixed(2)}
)} {/* Cash Summary */} Cash
Total Opening${report.cash.totalOpening.toFixed(2)}
Cash Sales${report.cash.totalCashSales.toFixed(2)}
{report.cash.totalCashIn > 0 &&
Cash In+${report.cash.totalCashIn.toFixed(2)}
} {report.cash.totalCashOut > 0 &&
Cash Out-${report.cash.totalCashOut.toFixed(2)}
}
Expected Total${report.cash.totalExpected.toFixed(2)}
Actual Total${report.cash.totalActual.toFixed(2)}
{report.cash.totalOverShort >= 0 ? 'Over' : 'Short'} ${Math.abs(report.cash.totalOverShort).toFixed(2)}
)}
) }