feat: bulk XML upload, period selector, and session persistence
- 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>
This commit is contained in:
@@ -30,3 +30,42 @@ export async function getResumenCfdi(año?: number, mes?: number) {
|
||||
const response = await apiClient.get(`/cfdi/resumen?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export interface CreateCfdiData {
|
||||
uuidFiscal: string;
|
||||
tipo: 'ingreso' | 'egreso' | 'traslado' | 'nomina' | 'pago';
|
||||
serie?: string;
|
||||
folio?: string;
|
||||
fechaEmision: string;
|
||||
fechaTimbrado: string;
|
||||
rfcEmisor: string;
|
||||
nombreEmisor: string;
|
||||
rfcReceptor: string;
|
||||
nombreReceptor: string;
|
||||
subtotal: number;
|
||||
descuento?: number;
|
||||
iva?: number;
|
||||
isrRetenido?: number;
|
||||
ivaRetenido?: number;
|
||||
total: number;
|
||||
moneda?: string;
|
||||
tipoCambio?: number;
|
||||
metodoPago?: string;
|
||||
formaPago?: string;
|
||||
usoCfdi?: string;
|
||||
estado?: string;
|
||||
}
|
||||
|
||||
export async function createCfdi(data: CreateCfdiData): Promise<Cfdi> {
|
||||
const response = await apiClient.post<Cfdi>('/cfdi', data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function createManyCfdis(cfdis: CreateCfdiData[]): Promise<{ count: number }> {
|
||||
const response = await apiClient.post<{ count: number; message: string }>('/cfdi/bulk', { cfdis });
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function deleteCfdi(id: string): Promise<void> {
|
||||
await apiClient.delete(`/cfdi/${id}`);
|
||||
}
|
||||
|
||||
@@ -34,3 +34,21 @@ export async function createTenant(data: CreateTenantData): Promise<Tenant> {
|
||||
const response = await apiClient.post<Tenant>('/tenants', data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export interface UpdateTenantData {
|
||||
nombre?: string;
|
||||
rfc?: string;
|
||||
plan?: 'starter' | 'business' | 'professional' | 'enterprise';
|
||||
cfdiLimit?: number;
|
||||
usersLimit?: number;
|
||||
active?: boolean;
|
||||
}
|
||||
|
||||
export async function updateTenant(id: string, data: UpdateTenantData): Promise<Tenant> {
|
||||
const response = await apiClient.put<Tenant>(`/tenants/${id}`, data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function deleteTenant(id: string): Promise<void> {
|
||||
await apiClient.delete(`/tenants/${id}`);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
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({
|
||||
@@ -23,3 +24,42 @@ export function useResumenCfdi(año?: number, mes?: number) {
|
||||
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'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { getTenants, createTenant, type CreateTenantData } from '@/lib/api/tenants';
|
||||
import { getTenants, createTenant, updateTenant, deleteTenant, type CreateTenantData, type UpdateTenantData } from '@/lib/api/tenants';
|
||||
|
||||
export function useTenants() {
|
||||
return useQuery({
|
||||
@@ -18,3 +18,25 @@ export function useCreateTenant() {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateTenant() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: string; data: UpdateTenantData }) => updateTenant(id, data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['tenants'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteTenant() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => deleteTenant(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['tenants'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user