- Add bulk XML CFDI upload support (up to 300MB) - Add period selector component for month/year navigation - Fix session persistence on page refresh (Zustand hydration) - Fix income/expense classification based on tenant RFC - Fix IVA calculation from XML (correct Impuestos element) - Add error handling to reportes page - Support multiple CORS origins - Update reportes service with proper Decimal/BigInt handling - Add RFC to tenant view store for proper CFDI classification - Update README with changelog and new features Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import * as cfdiApi from '@/lib/api/cfdi';
|
|
import type { CfdiFilters } from '@horux/shared';
|
|
import type { CreateCfdiData } from '@/lib/api/cfdi';
|
|
|
|
export function useCfdis(filters: CfdiFilters) {
|
|
return useQuery({
|
|
queryKey: ['cfdis', filters],
|
|
queryFn: () => cfdiApi.getCfdis(filters),
|
|
});
|
|
}
|
|
|
|
export function useCfdi(id: string) {
|
|
return useQuery({
|
|
queryKey: ['cfdi', id],
|
|
queryFn: () => cfdiApi.getCfdiById(id),
|
|
enabled: !!id,
|
|
});
|
|
}
|
|
|
|
export function useResumenCfdi(año?: number, mes?: number) {
|
|
return useQuery({
|
|
queryKey: ['cfdi-resumen', año, mes],
|
|
queryFn: () => cfdiApi.getResumenCfdi(año, mes),
|
|
});
|
|
}
|
|
|
|
export function useCreateCfdi() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (data: CreateCfdiData) => cfdiApi.createCfdi(data),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['cfdis'] });
|
|
queryClient.invalidateQueries({ queryKey: ['cfdi-resumen'] });
|
|
queryClient.invalidateQueries({ queryKey: ['dashboard'] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useCreateManyCfdis() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (cfdis: CreateCfdiData[]) => cfdiApi.createManyCfdis(cfdis),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['cfdis'] });
|
|
queryClient.invalidateQueries({ queryKey: ['cfdi-resumen'] });
|
|
queryClient.invalidateQueries({ queryKey: ['dashboard'] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteCfdi() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (id: string) => cfdiApi.deleteCfdi(id),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['cfdis'] });
|
|
queryClient.invalidateQueries({ queryKey: ['cfdi-resumen'] });
|
|
queryClient.invalidateQueries({ queryKey: ['dashboard'] });
|
|
},
|
|
});
|
|
}
|