'use client'; import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { DashboardShell } from '@/components/layouts/dashboard-shell'; import { Card, CardContent, Button, SortableHeader } from '@horux/shared-ui'; import { apiClient } from '@/lib/api/client'; import { formatCurrency } from '@/lib/utils'; import { exportToExcel } from '@/lib/export-excel'; import { useTableSort } from '@horux/shared-ui'; import { CfdiViewerModal } from '@/components/cfdi/cfdi-viewer-modal'; import { Eye, Download } from 'lucide-react'; import type { Cfdi } from '@horux/shared'; const EXCEL_COLUMNS = [ { header: 'UUID', key: 'uuid', width: 40 }, { header: 'Fecha', key: '_fecha', width: 15 }, { header: 'RFC Emisor', key: 'rfcEmisor', width: 15 }, { header: 'Nombre Emisor', key: 'nombreEmisor', width: 30 }, { header: 'RFC Receptor', key: 'rfcReceptor', width: 15 }, { header: 'Nombre Receptor', key: 'nombreReceptor', width: 30 }, { header: 'Total MXN', key: '_totalMxn', width: 15 }, { header: 'Forma Pago', key: 'formaPago', width: 12 }, ]; function prepareRows(data: any[]) { return data.map((c) => ({ ...c, _fecha: new Date(c.fechaEmision).toLocaleDateString('es-MX'), _totalMxn: Number(c.totalMxn || 0), })); } export default function EfectivoPage() { const [selectedCfdi, setSelectedCfdi] = useState(null); const { data, isLoading } = useQuery({ queryKey: ['drilldown-efectivo'], queryFn: async () => { const res = await apiClient.get('/alertas/drilldown/efectivo'); return res.data; }, }); const { sortedData, toggleSort, getSortIndicator } = useTableSort( data, { fecha: (c) => new Date(c.fechaEmision).getTime(), total: (c) => Number(c.totalMxn || 0), }, 'fecha', ); const handleExport = () => { if (!sortedData || sortedData.length === 0) return; exportToExcel(prepareRows(sortedData), EXCEL_COLUMNS, 'cfdis-pago-efectivo'); }; return ( {isLoading ? (
Cargando...
) : !data || data.length === 0 ? (
No hay CFDIs con pago en efectivo
) : (

{data.length} CFDIs con pago en efectivo

toggleSort('fecha')} /> toggleSort('total')} /> {(sortedData || []).map((cfdi: any) => ( ))}
UUID RFC Emisor Nombre Emisor RFC Receptor
{cfdi.uuid?.substring(0, 8)} {new Date(cfdi.fechaEmision).toLocaleDateString('es-MX')} {cfdi.rfcEmisor} {cfdi.nombreEmisor} {cfdi.rfcReceptor} {formatCurrency(Number(cfdi.totalMxn))}
)}
setSelectedCfdi(null)} />
); }