'use client'; import { useState } from 'react'; import { Header } from '@/components/layouts/header'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { KpiCard } from '@/components/charts/kpi-card'; import { PeriodSelector } from '@/components/period-selector'; import { useIvaMensual, useResumenIva, useResumenIsr } from '@/lib/hooks/use-impuestos'; import { Calculator, TrendingUp, TrendingDown, Receipt } from 'lucide-react'; const meses = ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic']; export default function ImpuestosPage() { const [año, setAño] = useState(new Date().getFullYear()); const [mes, setMes] = useState(new Date().getMonth() + 1); const [activeTab, setActiveTab] = useState<'iva' | 'isr'>('iva'); const { data: ivaMensual, isLoading: ivaLoading } = useIvaMensual(año); const { data: resumenIva } = useResumenIva(año, mes); const { data: resumenIsr } = useResumenIsr(año, mes); const formatCurrency = (value: number) => new Intl.NumberFormat('es-MX', { style: 'currency', currency: 'MXN', minimumFractionDigits: 0, }).format(value); return ( <>
{/* Tabs */}
{activeTab === 'iva' && ( <> {/* IVA KPIs */}
} subtitle="Cobrado a clientes" /> } subtitle="Pagado a proveedores" /> } trend={(resumenIva?.resultado || 0) > 0 ? 'up' : 'down'} trendValue={(resumenIva?.resultado || 0) > 0 ? 'Por pagar' : 'A favor'} /> } trend={(resumenIva?.acumuladoAnual || 0) < 0 ? 'up' : 'neutral'} trendValue={(resumenIva?.acumuladoAnual || 0) < 0 ? 'Saldo a favor' : ''} />
{/* IVA Mensual Table */} Histórico IVA {año} {ivaLoading ? (
Cargando...
) : (
{ivaMensual?.map((row) => ( ))} {(!ivaMensual || ivaMensual.length === 0) && ( )}
Mes Trasladado Acreditable Retenido Resultado Acumulado Estado
{meses[row.mes - 1]} {formatCurrency(row.ivaTrasladado)} {formatCurrency(row.ivaAcreditable)} {formatCurrency(row.ivaRetenido)} 0 ? 'text-destructive' : 'text-success' }`} > {formatCurrency(row.resultado)} 0 ? 'text-destructive' : 'text-success' }`} > {formatCurrency(row.acumulado)} {row.estado === 'declarado' ? 'Declarado' : 'Pendiente'}
No hay registros de IVA para este año
)}
)} {activeTab === 'isr' && ( <> {/* ISR KPIs */}
} /> } /> } /> } trend={(resumenIsr?.isrAPagar || 0) > 0 ? 'up' : 'neutral'} />
{/* ISR Info Card */} Cálculo de ISR Acumulado
Ingresos acumulados {formatCurrency(resumenIsr?.ingresosAcumulados || 0)}
(-) Deducciones autorizadas {formatCurrency(resumenIsr?.deducciones || 0)}
(=) Base gravable {formatCurrency(resumenIsr?.baseGravable || 0)}
ISR causado (estimado) {formatCurrency(resumenIsr?.isrCausado || 0)}
(-) ISR retenido {formatCurrency(resumenIsr?.isrRetenido || 0)}
ISR a pagar {formatCurrency(resumenIsr?.isrAPagar || 0)}
)}
); }