feat: facturación primer pago, fixes SAT/MP, autocompletado RFCs/conceptos
Backend: - Notificación email al admin cuando llega primer pago aprobado (sin factura auto) - Endpoints GET /pagos-sin-factura y POST /emitir-factura-pago para admin global - Fix vinculación org Facturapi Horux 360 (69f23a5a242e0af47a41fa0d) - Fix webhook MP: validación defensiva de x-signature header - Fix autocompleto RFCs: eliminado filtro por contribuyenteId - Fix autocompleto conceptos: eliminado filtro por contribuyenteId - SAT fixes: anti-bot CSF scraper, request reuse, date range fix, stale job thresholds - SAT sync request reuse across jobs para evitar agotar cuota diaria - Typo fix MP_ACCESS_TOKEN en .env - Trial invitations system backend Frontend: - Nueva página /admin/facturas-pendientes con tabla y emisión manual - Métrica 'Facturas pendientes' en /clientes (clickable) - Navegación onboarding FIEL/CSD corregida - Sidebar themes sincronizados - Fix SAT portal migration scraper (NetIQ) - Trial invitation acceptance pages
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
'use client';
|
||||
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@horux/shared-ui';
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription, Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '@horux/shared-ui';
|
||||
import { Header } from '@/components/layouts/header';
|
||||
import { DespachoSubnav } from '@/components/despachos/despacho-subnav';
|
||||
import { PeriodoSelector } from '@/components/periodo-selector';
|
||||
import { apiClient } from '@/lib/api/client';
|
||||
import { useAuthStore } from '@/stores/auth-store';
|
||||
import { useTenantViewStore } from '@/stores/tenant-view-store';
|
||||
import { usePeriodoStore, añoMesFromFechaInicio } from '@/stores/periodo-store';
|
||||
import { Building2, RefreshCw, Loader2, TrendingUp, FileCheck, DollarSign, AlertTriangle } from 'lucide-react';
|
||||
|
||||
interface Despacho {
|
||||
id: string;
|
||||
nombre: string;
|
||||
rfc: string;
|
||||
}
|
||||
|
||||
interface Stats {
|
||||
totalContribuyentes: number;
|
||||
ultimaExtraccion: string | null;
|
||||
@@ -20,14 +27,28 @@ interface Stats {
|
||||
tareasAtrasadas: number;
|
||||
}
|
||||
|
||||
const PLATFORM_SUPERSET = new Set(['platform_admin', 'platform_ti']);
|
||||
|
||||
export default function DespachoContribuyentesPage() {
|
||||
const role = useAuthStore(s => s.user?.role);
|
||||
const enabled = role === 'owner' || role === 'cfo';
|
||||
const platformRoles = useAuthStore(s => s.user?.platformRoles);
|
||||
const isPlatformStaff = platformRoles?.some(r => PLATFORM_SUPERSET.has(r)) ?? false;
|
||||
const enabled = role === 'owner' || role === 'cfo' || isPlatformStaff;
|
||||
const { fechaInicio } = usePeriodoStore();
|
||||
const { año, mes } = añoMesFromFechaInicio(fechaInicio);
|
||||
const { viewingTenantId, setViewingTenant } = useTenantViewStore();
|
||||
|
||||
const { data: despachos } = useQuery<Despacho[]>({
|
||||
queryKey: ['admin-despachos'],
|
||||
queryFn: async () => {
|
||||
const { data } = await apiClient.get<{ data: Despacho[] }>('/admin/dashboard/despachos');
|
||||
return data.data;
|
||||
},
|
||||
enabled: isPlatformStaff,
|
||||
});
|
||||
|
||||
const { data, isLoading } = useQuery<Stats>({
|
||||
queryKey: ['despacho-contribuyentes-stats', año, mes],
|
||||
queryKey: ['despacho-contribuyentes-stats', viewingTenantId, año, mes],
|
||||
queryFn: async () => {
|
||||
const { data } = await apiClient.get<Stats>(`/despachos/contribuyentes-stats?año=${año}&mes=${mes}`);
|
||||
return data;
|
||||
@@ -56,6 +77,31 @@ export default function DespachoContribuyentesPage() {
|
||||
<Header title="Despacho — Contribuyentes"><PeriodoSelector /></Header>
|
||||
<main className="p-6 max-w-7xl mx-auto">
|
||||
<DespachoSubnav />
|
||||
{isPlatformStaff && despachos && despachos.length > 0 && (
|
||||
<div className="mb-6">
|
||||
<label className="block text-sm font-medium text-muted-foreground mb-2">
|
||||
Ver despacho
|
||||
</label>
|
||||
<Select
|
||||
value={viewingTenantId || ''}
|
||||
onValueChange={(value) => {
|
||||
const d = despachos.find((x) => x.id === value);
|
||||
setViewingTenant(value || null, d?.nombre || null, d?.rfc || null);
|
||||
}}
|
||||
>
|
||||
<SelectTrigger className="w-full max-w-md">
|
||||
<SelectValue placeholder="Selecciona un despacho" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{despachos.map((d) => (
|
||||
<SelectItem key={d.id} value={d.id}>
|
||||
{d.nombre} ({d.rfc})
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isLoading ? (
|
||||
<div className="flex items-center gap-2 text-muted-foreground py-8 justify-center">
|
||||
|
||||
Reference in New Issue
Block a user